Css text box and button mismatch solution, css text box solution

Source: Internet
Author: User

Css text box and button mismatch solution, css text box solution

We first set the style for the input tag. The Code is as follows:

 

Html code

 

<Form> <input type = "text" name = "text1" id = "text1"/>

<Input type = "submit" name = "button" id = "button" value = "submit"/>

</Form>

CSS code

# Text1 {border: 1px solid red; height: 20px ;}

# Button {background: # FFFFFF; color: blue; border: 1px solid #000; height: 24px ;}

The text field is set to a height of 20 PX, and the button height needs to be set to 24px. Alignment is normal according to IE standards, but in Firefox, the text field and button height are staggered.

 

At this time, by setting the left floating (float: left) on the input tag, Firefox is compatible. the CSS code is as follows:

 

# Text1 {border: 1px solid #000; height: 20px; float: left ;}

# Button {background: # FFFFFF; color: # blue; border: 1px solid #000; height: 24px; float: left ;}

Of course, you can use CSS to control browser performance more specifically.

 

Summary: The button always uses the Quirks mode in height calculation. In Quirks mode, the border is calculated within the width of the element, rather than the standard mode, therefore, if you set the border on both the text and button, the height of the button is smaller than that of the text. Therefore, the text box must be aligned with the button, and the height of the button must be higher than that of the text. (The height of the button contains the height of the border, while text in the text box does not contain the height of the border .)

Related Article

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.