How to align checkboxes and their labels consistently cross-browsers

前端 未结 30 1838
有刺的猬
有刺的猬 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:00

    position: relative; has some issues in IE with z-index and animations like jQuery's slideUp/slideDown.

    CSS:

    input[type=checkbox], input[type=radio] {
        vertical-align: baseline;
        position: relative;
        top: 3px;
        margin: 0 3px 0 0;
        padding: 0px;
    }
    input.ie7[type=checkbox], input.ie7[type=radio] {
        vertical-align: middle;
        position: static;
        margin-bottom: -2px;
        height: 13px;
        width: 13px;
    }
    

    jQuery:

    $(document).ready(function () {
        if ($.browser.msie && $.browser.version <= 7) {
            $('input[type=checkbox]').addClass('ie7');
            $('input[type=radio]').addClass('ie7');
        }
    });
    

    The styling probably needs tweaks depending on the font-size used in

    PS:
    I use ie7js to make the css work in IE6.

提交回复
热议问题