Notes when writing CSS with input tags

Source: Internet
Author: User

The search box at the top of the flying fish sonar gave me a long headache, because it was impossible to get a unified style across browsers. There are two main problems: first, the height of the input tag cannot be uniform, and the height of Firefox and IE cannot be consistent; second, the input text in the input label with the attribute text in IE browser is not vertically centered as in the standard browser, but is displayed in the upper left corner of the input box.

To completely solve these problems in the search box, I use the style of the GreenGaint topic search box as the standard, the code is rewritten and measured in pixels. The actual difference between the <input> label in the default browser without any style sheets is measured.

The result shows that when the input tag type is text, the default height in Firefox and Safari is 22 pixels (including the upper and lower borders) and the width is 146 pixels (including the left and right borders ), in IE, the default height is 24 pixels, while the width is the same as that in Firefox and Safari, which is also 146 pixels. When the input tag type is submit, the height in Firefox is 23 pixels (including Shadow), and the width is 75 pixels. In Safari, the height is 21 pixels, the width is 73 pixels, the height is 25 pixels in IE, and the width is 73 pixels.

So what should I pay attention to when styling input tags? First, let's take a look at the following style-based search box with good performance in different browsers.

Example

To sum up, pay attention to the following points when writing CSS to the input Tag:

1. Do not set the height for the input label whose attribute is text. In this way, text in the input box in IE cannot be vertically centered. Although you want to center the text by setting the padding attribute later, you will find that it cannot achieve the same effect in Firefox and IE. The correct method is to directly set the padding attribute for the input tag and adjust the height of the input tag through the padding attribute. In this case, the text in IE is also displayed in the center.

2. The input tag does not inherit the font style and size of the parent element. You must directly declare the font-family and font-size attributes for the input tag.

3. Set the appropriate width attribute and padding attribute for the input tag whose attribute is text to ensure that the text appears within the appropriate range. Especially when a background image is used, make the text box and the background image size the same, which looks more beautiful.

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.