Why do a div and a button with the same styles render at different sizes?

后端 未结 1 999
借酒劲吻你
借酒劲吻你 2021-01-17 12:09

I have a page with some clickable

elements, and I want to change them to
相关标签:
1条回答
  • 2021-01-17 12:24

    Buttons and other input controls are rendered using the border-box model by default; i.e. content, padding and border all add up to the total width that you declare. They also often have some padding added by browsers arbitrarily according to their default stylesheets. As you quote, this is acceptable behavior and not a violation of standards; it's simply to accommodate rendering of OS-level GUI controls.

    To get your button to be the same size as your div, size it according to the content-box model (which is "the" original W3C box model) and zero out its padding:

    button.styled {
        -moz-box-sizing: content-box;
        -webkit-box-sizing: content-box;
        box-sizing: content-box;
        padding: 0;
    }
    

    jsFiddle demo

    0 讨论(0)
提交回复
热议问题