The HTML5 doctype in Chrome causes input fields to resize, while select fields remain unaffected

When the html5 doctype is prepended to the following HTML in current stable Chrome (48.0.2564.97), it changes the width of the <input> but not the <select>.

The <input> exceeds the boundaries of the <td> on the right side, while the <select> does not.

  1. What causes this behavior?
  2. How can I prevent it and still utilize html5?

HTML:

<html>
    <head>
        <style>
.input-cell > * {
    width: 100%;
}
        </style>
    </head>
    <body>
        <form>
            <table>
                <tr><td class="input-cell"><input name="note" type="text"></td></tr>
                <tr><td class="input-cell"><select name="formatted"><option></option></select></td></tr>
            </table>
        </form>
    </body>
</html>

Answer №1

To solve this issue, you'll need to use the box-sizing property in your CSS code (the first 3 lines of additional CSS). Even if you view the website with a different browser other than Chrome using the old code, you will still encounter the same problem. The box-sizing property will help solve the issue, except for Chrome, due to the default settings of Chrome's boxes. To address this, you must specify the padding, margin, height, and border properties of your inputs (the next 4 lines of additional code).

<!DOCTYPE html>

<html>
    <head>
        <style>
            .input-cell > * {
                width: 100%;
                -moz-box-sizing: border-box; 
                -webkit-box-sizing: border-box; 
                box-sizing:border-box;
                border: 1px solid #000000;
                padding: 0;
                margin: 0;
                height: 100%;
            }
        </style>
    </head>
    <body>
        <form>
            <table>
                <tr><td class="input-cell"><input name="note" type="text"></td></tr>
                <tr><td class="input-cell"><select name="formatted"><option></option></select></td></tr>
            </table>
        </form>
    </body>
</html>

By following these adjustments, your text boxes should align properly in all browsers. Feel free to further customize their appearance according to your preferences.

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

Is there a way to identify the font selected by the user's browser through Javascript?

Let's say the CSS on my web page for the body element looks like this: font-family: verdana, 'Liberation Sans', sans-serif; How can I determine if a user's browser is using 'Liberation Sans' font? I attempted to do something ...

Enhancing presentation with a multitude of pictures

I am currently in the process of developing a slideshow feature that includes an extensive collection of images for users to navigate through using 'next' and 'previous' buttons. At the moment, each time a user clicks on the navigation ...

Display the image before submitting it on Shiny platform

I'm currently developing a Shiny app that enables users to upload images directly to the server. I am wondering if there is a way to display the image on the screen without going through the process of uploading it first and then receiving the rendere ...

Allow undici fetch requests to use self-signed certificates

What is the correct way to execute fetch('https://localhost:8888') when dealing with a locally hosted HTTP server that uses a self-signed certificate (using fetch which is derived from undici)? ...

React component fails to display inline CSS

I am experiencing an issue with my React application. I have created an App component that is supposed to render an array of components on the screen, but for some reason, the inline CSS styles are not displaying. //App component import data from "./d ...

Having trouble importing the named export `{module}` from a non-ECMAScript module with TipTap and Nuxt?

I'm using TipTap with Nuxt and running into some issues that I can't seem to resolve. Despite following suggestions from the repository's issues, I keep encountering these specific errors: ERROR in /Volumes/Projects/nuxt/candy-hub-lerna/no ...

Guide on Validating and Updating an embedded item within a mongoDB Collection Document

How do I go about updating the values of an embedded object within a mongoDB document? The values displayed for {{service.id}} and {{service.username}} in the table template are correct. However, I am unsure of the correct way to access them within the sa ...

Unable to generate any output from the link when using 'react-router-dom'

Having trouble integrating a NavBar into my React app.js file. The Route files are loading correctly, but the Links set in the NavBar component aren't showing up on the page. Here is the code for NavBar: import React from 'react'; import { ...

Pop-up notification badge using AJAX technology

Is there a way to implement a notification number badge using Ajax, similar to what Facebook does? I can't provide an image here, but most people are probably familiar with the concept. It's like when you sign into Facebook and see a small number ...

Is it possible to transfer an image from the client to the NodeJS server and store it locally within the server itself?

Is there a way for me to upload an image from the client side, send it via an HTTP request (POST) to the server (NodeJS), and save it internally on the server? Whether using Jquery, XMLHttpRequest, or a form, I continue to face the same issue where I can& ...

Executing AJAX POST request with callback function

I successfully used this code for the get function to retrieve data. It works flawlessly and I am able to fetch the required data using this function. function getdata(getdatafrom, resultclass){ $.get(getdatafrom, function(data) { $(result ...

Issue: The property 'top' cannot be read as it is null

I'm trying to access the top of my footer, but I keep encountering this error message: Cannot read property 'top' of null Here is the HTML code: <footer class="footer" role="complementary" id="myfooter"> </footer> And in jQuer ...

Issues with CSS positioning are not being resolved in Chrome

I set up a Wordpress website and I'm trying to display two vertical banners outside of the main container. My CSS code seems to work fine on Firefox and IE, but on Chrome only the left banner is showing up. Any suggestions on what might be causing thi ...

Is there a way to instruct the code to select between two variables and align their values?

I have encountered a challenge while working on a unit test. The website I am testing is dynamic, causing the CSS Selector and xpath to frequently change. As a solution, I came up with the idea of using both CSS and xpath to retrieve the same text. Curren ...

Can someone guide me on how to utilize the onkeyup event within a bootstrap select element?

This code uses Bootstrap to filter elements, but I want to implement an onkeyup event to trigger a function. Whenever I type in the search input, I want it to automatically call myFunction(). <link href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/ ...

What is the reason behind a number having its final two digits transformed into zeros?

Query Hello, I was coding my discord bot and storing user IDs in a database. I plan to use these IDs to ping or assign roles to users. Issue However, I encountered a problem where the IDs in the database are being altered. For example, from 5336929053871 ...

Learn how to use canvas and JavaScript to draw lines that display x and y coordinates on top of the mouse pointer at the same time

Implement a functionality in which lines are drawn while the mouse button is held down and simultaneously display x & y coordinates on top of the mouse pointer during mouse movement using canvas and JavaScript. The issue arises when attempting to draw lin ...

What is the best way to align the main navigation at the center of

Even though I have utilized text-align: center, the style of .main-nav did not change. What is the most effective way to center this navigation menu? /***** Navigation *****/ .main-nav { font-family: 'Lato', Helvetica, Arial, sans-serif; f ...

Can you show me the way to open a single card?

Can someone assist me in making it so only one card opens when clicked, rather than all of them opening at once? Additionally, if there is already an open card and I click on another one, the currently open card should close automatically. If you have any ...

What is the best way to incorporate a specific term from the class into CSS styling

I am working on a webpage that includes '<a> <i> <label>' elements with specific classes. <a class="icon-home"></a> <label class="icon-pencil"></label> <i class="icon-display"></i> I want to ...