Text and form (Checkbox/radio) Element vertical alignment method, compatible with Firefox and IE.

Source: Internet
Author: User

These days when you make a form, you will always encounter the check box (checkbox) and the Radio Box (radio) and the text is not aligned with the problem, if the checkbox is not floating, but the text floats. In the front-end development process, the single (complex) box and the hint text behind them in the case of no setting, is not aligned, and in Firefox and IE in a very large difference. Even if the vertical-align:middle is set, it is still not perfectly aligned.

Workaround:
1, the text size must be even, such as 12PX.
2. Add text to label and Vertical-align:middle style.
3. Then remove the margins from the form element.

Case:

<!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head>    <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" />    <title>Test Vertical-align</title>    <style>        *{margin:0;}label{vertical-align:Middle}. Inputcheckbox{vertical-align:Middle;}Body{font-family:Tahoma;font-size:12px;}    </style></Head><Body>        <inputclass= "Inputcheckbox"name= "Test"value= "1"type= "checkbox">        <label>Test text X</label>    <BR/><BR/>        <inputclass= "Inputcheckbox"name= "Test2"value= "2"type= "Radio">        <label>Test text X</label>    <BR/><BR/>        <inputclass= "Inputcheckbox"name= "Text1"type= "text" />        <label>Text</label>        <inputclass= "Inputcheckbox"name= "Text1"type= "text" />        <label>Text</label>    <BR/><BR/>        <label>Test text</label>        <inputclass= "Inputcheckbox"name= "Button1"type= "button"value= "button" />    <BR/><BR/>        <Selectclass= "Inputcheckbox"name= "Select1">            <option>Test text</option>        </Select>        <label>Test text</label></Body></HTML>

Text and form (Checkbox/radio) Element vertical alignment method, compatible with Firefox and IE.

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.