Why are input sizes not consistent across elements?

I recently discovered that some elements calculate their size using the following formula:

width = width - width_border_size * 2
height = height - height_border_size * 2

However, the <input> element does not adjust its size accordingly.
How can I resolve this issue? Below is my code:

.options_display {
    display: flex;
    flex-direction: column;
    flex-wrap: nowrap;
}

.options_style * {
    text-align: center;
    font-size: medium;
    font-family: arial;
    padding: 0px;
    margin-bottom: 2px;
    width: 225px;
    height: 25px;
}

p {
    margin: 0px;
}

[hidden] {
    display: none;
}
<!DOCTYPE html>
<html>
    <head>
        <title>Test</title>
        <meta name="viewport" content="width=device-width">
    </head>
    <body onload="">    
        <!-- Disable, hide first option -->
        <div style="float: left; position: relative; left: 50%;">
            <div style="float: left; position: relative; left: -50%;">
                <div class="options_display options_style">
                    <select>
                        <option>Select test</option>
                        <option>Option 0</option>
                        <option>Option 1</option>
                        <option>Option 2</option>
                    </select>
                    <input type="number" placeholder="Input test 0">
                    <input type="number" placeholder="Input test 1">
                    <button onclick="">Button test</button>
                    <p id="text_id">Test</p>
                </div>
            </div>
        </div>
    </body>
</html>

Edit: Attempted to create a specific class for inputs and calculated the height and width with border sizes, but the resulting height was not precisely 25, it was around 24.6 (or .4, possibly). Maybe considering the font size in the calculation could be a solution, although unsure how to achieve this.

Answer №1

To resolve the issue, it is recommended to apply box-sizing: border-box to all elements. By default, the value is set to content-box, which implies that any additional padding and border widths specified by the vendor will be included in the overall width and height.

Many users opt for a CSS reset for this reason as most resets automatically include the following rule:

* {
  box-sizing: border-box;
}

Below is a demonstration of how this can be implemented:

* {
  box-sizing: border-box;
}

.options_display {
    display: flex;
    flex-direction: column;
    flex-wrap: nowrap;
}

.options_style * {
    text-align: center;
    font-size: medium;
    font-family: arial;
    padding: 0px;
    margin-bottom: 2px;
    width: 225px;
    height: 25px;
}

p {
    margin: 0px;
}

[hidden] {
    display: none;
}
<!DOCTYPE html>
<html>
    <head>
        <title>Test</title>
        <meta name="viewport" content="width=device-width">
    </head>
    <body onload="">    <!-- Disable, hide first option -->
        <div style="float: left; position: relative; left: 50%;">
            <div style="float: left; position: relative; left: -50%;">
                <div class="options_display options_style">
                    <select>
                        <option>Select test</option>
                        <option>Option 0</option>
                        <option>Option 1</option>
                        <option>Option 2</option>
                    </select>
                    <input type="number" placeholder="Input test 0">
                    <input type="number" placeholder="Input test 1">
                    <button onclick="">Button test</button>
                    <p id="text_id">Test</p>
                </div>
            </div>
        </div>
    </body>
</html>

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

Having trouble getting Bootstrap to function correctly on an HTML page

I am facing difficulty in identifying the issue. I have replaced the body content with that of another website, which works perfectly fine. However, despite trying to initialize bootstrap elements through both relative paths and CDN, they are not showing u ...

Select from a variety of backgrounds using the dropdown menu on the site

I seem to be struggling with javascript and php, but I know that in order to make this function properly, I need to utilize both languages. My goal is to set up a "select box" featuring 4 different images. There will be a default image displayed, but user ...

Tips for allowing only one checkbox to be selected

Looking at the code snippet below, my checkbox behaves like a button. I would like to make it so only one can be checked at a time. Currently, the checkbox buttons change color when clicked and all buttons are checkable simultaneously. PS. I want to ensur ...

The HTML 5 video is not functioning properly on an iPad, and the layout of the iPad has black areas on the sides

Having some trouble with an HTML 5 project where the video plays on Chrome and Safari PC browsers but not on iPad. The task at hand is to get it working in portrait mode only, with the video playing when tapped/clicked. <!doctype html> <!--[if ...

Issues with the ReactJS dropdown menu persist despite attempts to fix the problem with

I've been trying to add a blur backdrop filter to my dropdown menu in a React JS project, but it just doesn't seem to work. It works perfectly fine with all other elements except this one. What I'm looking for is to have the same blur effec ...

Looking for assistance with removing hardcoding in HTML and jQuery?

Currently working on a biography page for my company's website that features a grid layout of the employees' profile pictures. Each picture should be clickable, causing the screen to fade to gray and display an overlay with the respective person& ...

Submitting modal form information using AJAX to PHP

As a novice in the realm of web programming, I find myself seeking some guidance to untangle a riddle. Regrettably, my grasp of the basics still leaves much to be desired. Within my main page, view.adminsettings.php, I've designated a Navigation DIV ...

Activate Bootstrap button functionality with JavaScript

Hey team, I've got a Bootstrap button on my HTML page: ..... <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> ... <div class="accept-btn"> <button type="button" class="bt ...

"Despite using 'vertical-align: middle' on table cells, the alignment to the middle is not achieved when using AlphaImageLoader in IE6

I am currently working on aligning text within table cells that have a PNG Transparent background. To achieve this in IE6, I am using the filter:progid:DXImageTransform.Microsoft.AlphaImageLoader() method. However, I am facing an issue where the text is no ...

How Bootstrap Navigation is negatively impacting the width of the website

I am experiencing a problem with site width changes in the navigation. I have checked margins and padding, but couldn't find a solution to fix the issue. It seems like the row element is causing the problem, but I'm not sure why. Please assist me ...

What is the best way to ensure a container adjusts perfectly to its contents without constraining the contents to their minimum width?

Imagine you have a div with a flexible width (like min-width 200px and max-width 1000px). Let's refer to this div as Div1. The goal is to enclose this div in a parent div that adjusts its size to fit Div1 without impacting Div1's width whatsoever ...

The scrolling function in CSS is malfunctioning

I encountered a scroll-x issue in CSS Here is the HTML code snippet: <div id=main_user_chat_tab_div class="chat-container_div" style="border:4px solid #F00;"> <div id="chat_box_win" class="chat_box_win" style="position:relative;"></div ...

There is an issue with my HTML due to a MIME type error

I am currently facing an issue with my project. I have developed a node js server and now I want to display an HTML file that includes a Vue script loading data using another method written in a separate JS file. However, when I attempt to load the HTML f ...

The border below the menu is not extending to the entire width of the page

Seeking assistance to create a menu with bordered items that have a border on the right and a full-width bottom border. Facing an issue where the bottom border only spans the container width, rather than the entire screen. The use of a container class is n ...

Update the style dynamically in Angular using an ngFor directive and an array of data

Is there a way to dynamically set the width using data from an array in Angular? The usual approach doesn't seem to work. How can I solve this issue? <div *ngFor="let item of products"> <div [style.width.px]="item.size" class="Holiday"&g ...

The Angular directive can alter the scope, but this capability is lost when using setTimeout

// javascript var a = angular.module('minimalReproApp', [ ]) a.controller('MainCtrl', function($scope) { $scope.fileData = {} $scope.fileData.xmlData = "ControllerScope"; }).directive('dropzone', func ...

Is it possible to create a BS Modal without a backdrop, overlay, and with the ability to focus input fields when displayed

When using BS modals without a backdrop and with custom overlay styling to make them look like floating windows (for example, for cookie consent), I am aware that setting button elements to be clickable requires the following: .modal { pointer-events: non ...

What causes the HTML form to display inconsistently when the page is reloaded in the browser?

Why is it that each time this valid HTML5 document is reloaded in the browser, the font and box sizes change randomly? This behavior seems to occur without any logical explanation. Any ideas on why this might be happening? <!doctype html> <htm ...

Tips on concealing and deactivating the fullscreen option in flowplayer

Could someone please assist me in resolving this issue? I've been attempting to hide the fullscreen button from the flowplayer, but so far, I haven't found a solution. Below is my JavaScript code: <script> $f("player", "flowplayer/flowpla ...

Displaying a Bootstrap card with ellipsis text-overflow following a short excerpt of text

When working on a web application using the Bootstrap library, I utilized card classes. The goal was to truncate text that was too long, as shown in the image below: https://i.sstatic.net/4wKyT.jpg However, the result I achieved looked different than exp ...