CSS goes deep into the label and input alignment!

Source: Internet
Author: User

I think many people will encounter the problem of alignment between label and input.

This is not difficult, but it is a headache to be compatible with IE.

Refer to the front-end source code of each major portal website. One method is recorded as follows:

Html is really simple:

 

CSS:

Label {display: inline-block; padding: 0 10px; vertical-align: middle;} input {outline: none; border: 1px solid rgb (216,216,216); padding: 2px 10px 2px 10px;} input [type = "text"] {height: 14px; line-height: 14px; border-radius: 5px; padding: 10px 10px; vertical-align: middle; color: #666;} input [type = "button"] {padding: 0px 10px; height: 40px ;}

. Login-box p {vertical-align: middle; padding: 10px 10px ;}


The main problem here is
The paddng method is used in input.

Use padding to open the input. At this time, the input height is only 14px, and then set line-height to 14px;

With vertical-align vertically centered, the text in the input can be vertically centered.

To vertically align input and label, you only need to set vertical-align of their parent node to middel.

Set the height to the same as the line-height. Of course, the height must be higher or equal than the actual height of input.

This is the actual height.

Here we record the height of the CSS box model:



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.