Vertically aligning a checkbox

后端 未结 7 946
后悔当初
后悔当初 2020-12-29 19:52

I have looked at the different questions regarding this issue, but couldn\'t find anything that works due to limitations in my markup.

My markup looks like so (unfor

相关标签:
7条回答
  • 2020-12-29 20:45

    Its not a perfect solution, but a good workaround.

    You need to assign your elements to behave as table with display: table-cell

    Solution: Demo

    HTML:

    <ul>        
        <li>
            <div><input type="checkbox" value="1" name="test[]" id="myid1"></div>
            <div><label for="myid1">label1</label></div>
        </li>
        <li>
            <div><input type="checkbox" value="2" name="test[]" id="myid2"></div>
            <div><label for="myid2">label2</label></div>
        </li>
    </ul>
    

    CSS:

    li div { display: table-cell; vertical-align: middle; }
    
    0 讨论(0)
提交回复
热议问题