Different nature reasons for input and select widths on different browsers

Source: Internet
Author: User

There is often a problem with form development, and input and select are the most commonly used two tags, but one problem is tricky. Input and select are two different and models, and if you simply set the width of both to the same, the following effect will appear:

<! DOCTYPE html>


And it is in all browsers, the following directly to see the box model layout in each browser will be at a glance;

Chrome:


Firefox

ie: (here ie to generational, IE8 before is a generation, IE9 after the generation, see figure)


These two tags are significantly different on different browsers, summarizing:

Model: Border + realwidth

ie9+->ie8-, Firefox, Chrome

Select

2*2 + 98-0*2 + 1*2 + 98 + 1*2 + 100 (102 100 100 102)

Input

2*2 + +-1*2 + 1*2 + 102--1*2 + 100 (104 102 102)

Either way, there will be more than 2px (ie8-seems to be 102, but the effect is more than 2px), this is enough to make Virgo crazy! I am not a Virgo, but in the course of practice is also crazy, not to explore the essence of the cause and solution is really unsettling, fortunately there is a solution! In fact, add an inner margin, all doubts will be solved.

The CSS width style of the Select, which contains the border and padding, that is: realwidth=css width.

The CSS width style of input does not include the border and inner spacing, realwidth=css width + border + padding.

the solution is as follows: ( just Chrome's layout, you can try it in each browser is a rule-based)

<! DOCTYPE html>

Summarize:

Set CSS width border for the select CSS width=input padding

Done perfectly!

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Different nature reasons for input and select widths on different browsers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.