How to change a DIV padding without affecting the width/height ?

后端 未结 5 687
死守一世寂寞
死守一世寂寞 2020-12-22 18:52

I have a div that I want to specify a FIXED width and height for, and also a padding which can be changed without decreasing the original DIV width/height or increasing it,

5条回答
  •  [愿得一人]
    2020-12-22 19:28

    Declare this in your CSS and you should be good:

    * { 
        -moz-box-sizing: border-box; 
        -webkit-box-sizing: border-box; 
         box-sizing: border-box; 
    }
    

    This solution can be implemented without using additional wrappers.

    This will force the browser to calculate the width according to the "outer"-width of the div, it means the padding will be subtracted from the width.

提交回复
热议问题