在不改变整体宽度的情况下添加填充

2022-01-18 00:00:00 overflow grid padding css

如何在不添加预定义宽度的情况下为元素添加填充?

How can I add padding to an element without adding on top of the predefined width?

最好定义一列的宽度来为布局制作一个干净的网格;但也想为列内的内容添加填充.有什么方法可以指定吗?

It's good to define the width of a column to make a clean grid for the layout; but also wants to add padding to the contents inside the column. Any way to specify that?

推荐答案

element { 
    -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
    -moz-box-sizing: border-box;    /* Firefox, other Gecko */
    box-sizing: border-box;         /* Opera/IE 8+ */
}

相关文章