如何给float:right的元素添加padding而不会出现混乱?难道padding不应该在内部起作用而不是在外部吗?看看在绿色部分添加一些padding时会发生什么:http://lauradifazio.altervista.org/cms/。
contentWidth = availableWidth - margin - border - padding
contentWidth = 200px - (2x5px) - (2x1px) - (2x10px)
contentWidth = 200px - 10px - 2px - 20px
contentWidth = 168px
**note that the (2xNN) refers to the fact that you have to
consider both the impact to both the left and right side
of the element in the total.
width: 168px;
border: 1px <color> <type>;
padding: 10px;
margin: 5px;
box-sizing
CSS属性强制使用其他盒子模型来定义您想要的盒子模型如何工作,但在可能的情况下应使用标准盒子模型。元素的宽度不包括内边距。如果您向元素添加内边距,则必须相应地减小宽度和高度。
190px
而不是 200px
,因为你有 5px 的内边距。