css - Make a button fill the full width of container element? -
i'm converting using div
's buttons actual buttons, , need make buttons fill full width of container.
code:
.container { background-color: #ddd; padding: 10px; max-width: 500px; margin-left: auto; margin-right: auto; } .button { display: block; background-color: #bbb; margin: 10px; padding: 10px }
<div class="container"> <div class="button"> fills full width </div> <button class="button"> not fill full width </button> </div>
adding display:block
.button
not work (although i'm sure has got part of @ answer?), , neither left: 0; right: 0
. width: 100%
sort of works, ignores container's padding property , makes button go close right side of container.
here jsfiddle: http://jsfiddle.net/mn40mz2n/
add "box-sizing: border-box" property elements. width , height properties include padding , border, not margin. ensure measurements across elements correct , take account padding. display: block , width: 100% correct way go full width need remove left/right margin on button pushes outside containing element.
* { box-sizing: border-box } .container { background-color: #ddd; padding: 10px; margin: 0 auto; max-width: 500px; } .button { background-color: #bbb; display: block; margin: 10px 0; padding: 10px; width: 100%; }
for more information on box-sizing property, read mdn docs.
Comments
Post a Comment