Variation in element widths and CSS widths

While inspecting an element in FF, it displays a width of 225px.
However, the applied CSS sets the width to 207px for this element.
The discrepancy may be due to Bootstrap and varying resolutions. Is there a tool available to identify change sources?
I'm looking for a tool that can alert me when specific properties are altered.
Thank you in advance for any assistance

These details are extracted from FF Inspector in two different states:
Element is input[type=text]

<input aria-invalid="true" class="invalid" name="jform[university]" id="jform_university" value="" required="" aria-required="true" type="text">


State 1: Width = 225px

*::-moz-selection {
                background: #F9924F none repeat scroll 0% 0%;
                color: #FFF;
            }
            element {
            }
            select, textarea, input[type="text"], ...
            ...... continued ...........
            html {
                font-size: 100%;
            }

State 2: Width = 207px

*::-moz-selection {
                background: #F9924F none repeat scroll 0% 0%;
                color: #FFF;
            }
            element {
            }
            select, textarea, input[type="text"], ...
            ...... continued ...........
            html {
                font-size: 100%;

Answer №1

It appears that there is a discrepancy between the width:207px set on your input and the actual 225px width displayed on the page.

This issue likely stems from the css box model computations.


The default mode, box-sizing:content-box, calculates the size of an element based solely on its content. However, you may want to consider using box-sizing:border-box for more natural behavior. To implement this change, adjust the box-sizing property on the element.

https://i.stack.imgur.com/7Roxl.jpg
(source: binvisions.com)

content-box

In the content-box model, the width/height is determined only by the element's content, with padding, border-width, and margin extending beyond those dimensions.

Therefore, when you specify width:207px in this model, it interprets as "the content should be 207px wide," considering padding and border-width additional to that measurement.

border-box

In contrast, the border-box model includes padding and border-width in the calculation, resulting in the sum of content + padding + border-width as the total width.

If you set width:207px with padding:8px and border-width:1px, the available space for content would be 189px (207px - 2*8px - 2*1px).


solving the problem

To address this issue, you can apply the following:

select, textarea, input[type="text"], input[type="password"], input[type="datetime"], input[type="datetime-local"], input[type="date"], input[type="month"], input[type="time"], input[type="week"], input[type="number"], input[type="email"], input[type="url"], input[type="search"], input[type="tel"], input[type="color"], .uneditable-input {
    width: 207px;
}

select, textarea, input[type="text"], input[type="password"], input[type="datetime"], input[type="datetime-local"], input[type="date"], input[type="month"], input[type="time"], input[type="week"], input[type="number"], input[type="email"], input[type="url"], input[type="search"], input[type="tel"], input[type="color"], .uneditable-input {
    padding: 0 8px;
    border: 1px solid #CACACA;
}

Since you are currently in the content-box mode, the computed width will be 207px + 2*8px + 2*1px, resulting in the observed 225px.

To resolve this, apply box-sizing:border-box to the element. However, note that this adjustment may impact other styles. Alternatively, opting for width:189px might be a better solution.

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

Switch div and expand/shrink the rest

Apologies for what might seem like a trivial question, but after working for a few hours now, I'm finding it difficult to wrap my head around this. My initial instinct is to handle this by manipulating the entire div structure with JavaScript, but I c ...

What is the best way to arrange a bootstrap .container?

I've been struggling to position a content DIV on a bootstrap carousel, but so far I haven't been successful in figuring it out. Below is a screenshot of the current output from my code, which is not what I am aiming for. What I'm trying t ...

Prevent the hover() effect from affecting all div elements at once

I am aiming to achieve a function where hovering over a div with the "rectangle" class will display another div with the "description" class. Initially, the description div will have a display value of "none", but upon hovering, it should become visible. ...

Having trouble loading NEXT JS images when the file path is stored in a variable?

I'm working with Next.js for my coding project and I have a array of images that I need to incorporate into my application. CODE1 <Image src={require("../assets/image1.png")} /> This code snippet works perfectly fine and displays the ...

JavaScript utilizing an API to retrieve specific data values

Below is some API Data that I have: [ { "symbol": "AAPL", "name": "Apple Inc.", "price": 144.98, "changesPercentage": -1.22, "change": -1.79, ...

Experiencing difficulties with positioning text beside an image

Hello everyone, I'm a first-time poster seeking some assistance. I'm currently tackling an assessment and am struggling with the final part. The task involves creating a picture card with an image at the top, a circular image to the side, and tex ...

Although PhoneGap resolution remains consistent, the outcomes may vary

I seem to be facing a similar issue as discussed in this post on Stack Overflow: Screen Resolution On A PhoneGap App My problem is that I have both an iPad and an Android tablet, both with a resolution of 1024 pixels across. However, while my screen displ ...

An HTML table featuring rows of input boxes that collapse when the default value is not filled in

My table is populated with dynamic rows of input boxes, some of which may have a default value while others return an empty string ''. This causes the table to collapse on those inputs. <tr *ngFor="let d of displayData"> < ...

Switch up the font style of the title element

Is it possible to modify the font-family of the title attribute in an input field using either JavaScript or jQuery? <input type="text" title="Enter Your Name" id="txtName" /> ...

Style formatting is applied to the addition of fresh content on a webpage

As I develop a front end page that pulls data from multiple sources, my goal is to allow for dynamic addition of new sources without the need for code changes. This includes the ability to add new source URLs on the fly. Additionally, certain data sources ...

"Troublesome issue with Bootstrap push and pull functionality not functioning correctly

I am currently experiencing issues with Bootstrap push and pull functionality. While the mobile view appears to be working correctly, the web view is shifted to the left. Any assistance on this matter would be greatly appreciated. Below is the code that i ...

What is the best way to include start and end labels on Bootstrap's progress bars?

Is there a way to add start and end labels directly below the progress bar in Bootstrap? Here is an example of what I want: [||||||||------------] <Start Label> <End Label> I have been searching for a solution, but it seems ...

Creating a larger spinning div using CSS3 animation

I am looking to add a fun hover effect to my div where it spins and zooms in at the same time. Here is what I have so far: [html] div class="myMsg">> <p id="welly" style="color: #009">Welcome to Y3!<br><br><br>T ...

How can I create a one-column layout in CSS grid where one element automatically fills the remaining space after the other elements have taken their own auto widths?

I want a flexible layout with auto width columns for future additions. Avoiding extra wrappers is preferred. CSS grid is the preferred method over flexbox (although flexbox can achieve it with wrappers). This layout is intended for a navigation bar Here&a ...

Creating a border indentation for a table row using the <tr> tag

In my database, there is a table that shows the parent-child relationship. Check out this link for more details The HTML structure of the table is as follows: <table> <tr class="parent_row"> <td >1</td> <td>2</t ...

Issue with border in a nested table within an HTML table

I am faced with an issue in styling nested tables. My goal is to have borders on both tables, but I specifically need only the bottom border of the inner table without the top, right, and left borders. The default border style can be achieved using the fol ...

Update the div element without needing to reload the entire page

Is there a way to reload a div tag without refreshing the entire page? I understand this question has been asked before, but I want to make sure I have a clear understanding. <p>click HERE</p> <div class="sample"> <?php functi ...

Adding Bootstrap to container-specific styling in SCSS

I am currently in the process of upgrading to the most recent version of reactstrap & Bootstrap. Previously, I had reactstrap in my package.json file and downloaded Bootstrap SCSS in my client/src/styles/bootstrap directory. Now, my updated package.json c ...

What steps can I take to have the text extend beyond the background at both the top and bottom edges?

I am attempting to replicate this design using CSS: So far, this is what I have achieved: .container{ height: 30px; margin-bottom: 10px; } .redLine{ background-color: red; opacity: 0.5; height: 20px; border-radius: 5px; text-align: ce ...

Internet Explorer 8 comes with excess padding at the top and bottom, causing un

Why is IE 8 adding unnecessary padding to a div? I have checked the styling and nothing seems out of place. Can someone assist with this issue? Html The highlighted div in blue is the main concern. .block { clear: both; } .inline { float: lef ...