How to align checkboxes and their labels consistently cross-browsers

前端 未结 30 1841
有刺的猬
有刺的猬 2020-11-22 05:56

This is one of the minor CSS problems that plagues me constantly. How do folks around Stack Overflow vertically align checkboxes and

30条回答
  •  死守一世寂寞
    2020-11-22 06:11

    With an input type checkbox wrapped inside the label and floated to the left like so:

    
    

    this worked for me:

    label.checkbox {
        display: block;
    }
    .checkbox input {
        float: left;
        height: 18px;
        vertical-align: middle;
    }
    .checkbox span {
        float: left;
        line-height: 18px;
        margin: 0 0 0 20px;
    }
    

    Make sure the height of the is identical to the line-height of the (blocklevel) .

提交回复
热议问题