The font size of the <input> element is constantly fluctuating, causing

Basically, I am working on this code snippet for a calculator:

#calculator {
  background-color: #212121;
  border-radius: 10px;
  overflow: hidden;
  display: inline-block;
}

#functionality {
  width: 100%;
  height: 100%;
  margin: 15px 5px 5px 15px;
  overflow: hidden;
}

#display_calc {
  max-width: 91%;
  width: 91%;
  height: 70px;
  background-color: #1a1a1a;
}

#display {
  min-width: 100%;
  max-width: 100%;
  height: 100%;
  font-size: 50px;
  background-color: rgba(0, 50, 0, 5);
  color: white;
  border: none;
}
<div id="calculator">
  <div id="functionality">
    <div id="display_calc">
      <input id="display">
    </div>
  </div>
</div>

However, I'm facing an issue where changing the font size of the display input element causes the width to expand excessively. Despite trying various solutions and adding restrictions to the div elements, the maximum width property set for the input field does not seem to work as expected.

Answer №1

To adjust the input to match the screen width, simply delete the display: inline-block; property from the #calculator element - this should do the trick. However, if you prefer to maintain an inline display, you can also include the width: 100%; property in the #calculator style rule.

Answer №2

The issue arises from the combination of inline-block and percentage width. To resolve this, it is necessary to specify a width (or use max-width for the inline-block element) and eliminate certain other styles.

#calculator {
  background-color: #212121;
  border-radius: 10px;
  display: inline-block;
  width: 100%; /* or max-width: 100%; */
}

#functionality {
  margin: 15px 5px 5px 15px;
}

#display_calc {
  height: 70px;
  background-color: #1a1a1a;
}

#display {
  max-width: 100%;
  height: 100%;
  font-size: 50px;
  background-color: rgba(0, 50, 0, 5);
  color: white;
  border: none;
}
<div id="calculator">
  <div id="functionality">
    <div id="display_calc">
      <input id="display">
    </div>
  </div>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Hover over parts of an image to bring attention to them

I am interested in developing a webpage featuring a black and white image of 5 individuals. When hovering over each person, I would like them to illuminate and display relevant information in a dialog box next to them. Do you have any tips on how I can ac ...

How can I make a div blur as I scroll through the page

How can I make each item in my timeline focused one at a time as the user scrolls, instead of having all items in focus simultaneously? Any ideas or suggestions would be appreciated. Here is my fiddle and here is my code $(document).ready(function(){ ...

Guide on using a single submit button for two separate HTML forms

Is it possible to use the same submit button for two different HTML forms on one page? I want both forms to have the same action and be handled by the same servlet. <form action = "add"> Enter first number: <input type = " ...

Is it possible for the font size to adjust based on the heading (h1, h2, h3) I choose when using CSS to specify a particular font size?

What will happen if the following HTML code is used: <h1> This is text</h1> <h2> This is also text</h2> and CSS is applied to change the font size like this: .h1 { font-size: 30px } .h2{ font-size: 30px } Will both texts ...

What is the best way to ensure that my multiple choice code in CSS & JS only allows for the selection of one option at a time? Currently, I am able

I'm currently facing a small issue that I believe has a simple solution. My knowledge of Javascript is limited, but I am eager to improve my skills in coding for more visually appealing websites. My problem lies in the code snippet below, where I am ...

Tips on adjusting the width so it aligns with the text rather than the entire width using Bootstrap

My title is currently taking up the entire row, but I want it to only be as wide as the text itself and not extend to the width of the parent row. Any suggestions on how to achieve this? <head> <meta charset="UTF-8" /> <met ...

Ensure that only one button can be selected at a time for non-radio button elements in the

This is the code snippet I am working with $(document).ready(function(){ $("a.btn1").click(function() { $(this).find("i").toggleClass("fa-thumbs-o-up fa-thumbs-o-down"); }); $("a.btn2").click(function(){ $(this).fi ...

I'm trying to find a way to access a particular field within an HTML document using JavaScript in Node.js. Can anyone

<Response> <SMSMessageData> <Message>Delivered to 1/1 Total Cost: NGN 2.2000</Message> <Recipients> <Recipient> <number>+9109199282928</number> <cost>NGN 2.2000&l ...

Nurturing the growth of parents past the development of their

I am working with a parent container that contains a div with text inside: <div id="parent"> <div id="text"></div> </div> Here is the CSS rule I am using for them: parent{ clear:both; background:#f3f3f3; min-height:180px; } text{ ...

problem with saving session data

I am attempting to access data from another page using session storage. On my initial page, named home.html function go_to_faq(qnum){ window.open('FAQ.html', '_blank'); sessionStorage.setItem('key2', qnum); } <a s ...

What impact does reducing the window size have on my header?

While working on a website with a navigation bar, I encountered an issue where the navbar was not responsive. When the window size was reduced, the nav bar shifted to an awkward position vertically, as shown in the first image. The navbar shifts below the ...

Incorporating Keyboard Features into Buttons

How can I toggle the page selectors in #pageList using a keyboard shortcut instead of clicking on the .togglePL button? I've tried looking up solutions online and asking questions here, but haven't found a working solution yet. Below is the code ...

What's the issue with my ExpressJS req.query not functioning as expected?

My NodeJS repl setup includes an input, button, and h1 element. The goal is to update the HTML inside the h1 element with the value of the input upon button click. Here's a glimpse of my code: index.js: const Database = require("@replit/database ...

I'm struggling to position the four divs in each of the two rows similar to the example provided. Can anyone help me figure this

I need help figuring out how to position 4 divs in a row so that when one is clicked and expands with additional information, it pushes the bottom div down. All 8 divs have the same class. I attempted using display: inline-block, but all the lower 4 divs m ...

Modifying the href attribute of links within various occurrences of an element using jQuery based on its content

Here is an illustration of a recurring element on a webpage <td class=" market all"> <a href="linktosomesite?param=123" target="_blank">123</a> </td> Similar elements change the parameter, resulting in links like: <td clas ...

Modifying the information depending on the option chosen from the dropdown menu using angularJS

I have a dropdown menu where I can choose between two options, and when selected, the corresponding data is displayed. However, I would like to display the data that is inside a div tag instead. Check out this Fiddle Demo HTML: <div ng-controller="Ct ...

What are some ways to make the parent div grow based on the width, padding, margin, or box of the child div

Is it possible to expand a parent div with a child div and how can I achieve this? I have created a JSFiddle with some code included. CSS body { background: gray; } div.page { color: white; background: black; max-width: 72em; margin: ...

How come child elements are clipped in IE versions 9 and above when using the border-radius property with a fixed value?

When applying css border-radius:[some value] to a parent element and having a fixed positioned child element, I noticed that in Internet Explorer the child element appears to be 'clipped' into the parent. However, if I use border-radius:0 in the ...

Creating aesthetically pleasing and uniform rows of responsive Bootstrap 4 cards with consistent heights

I'm a beginner in the world of design and Bootstrap, so please be patient with me. My goal is to create a series of cards that have equal height and width (responsive, not fixed) in each row. In other words, I want all the cards to be as tall and wid ...

Styling the "Browse" button for different web browsers

Here is the code snippet I am working with: HTML: <form> <input id = "file" type="file" /> <div id="custom_button">custom button</div> </form> Jquery: $("#custom_button").on("click", function () { $("#file"). ...