[英]Is styling css with nested <div> always commutative?
I am trying to understand whether the order in which you define css styling using div tags matters.我试图了解您使用 div 标签定义 css 样式的顺序是否重要。
Is:是:
<div class="some styling 1"> <div class="some styling 2"> Some content </div> </div>
Always the same as:始终与以下内容相同:
<div class="some styling 2"> <div class="some styling 1"> Some content </div> </div>
? ?
Thanks!谢谢!
Clearly not, if you were for instance to put显然不是,例如,如果你把
border: 2px solid #000000;
padding: 5px;
on some styling 1
, and padding: 5px;
在
some styling 1
和padding: 5px;
on some styling 2
在
some styling 2
The first instance will produce a box with a border on the outside box and the content will have a padding
of 5px
relative to the border
, plus 5px
of padding
relative to the inner box, meaning the content will have 10px padding
and an outer border.第一个实例将在外框上生成一个带有边框的框,并且内容将具有相对于
padding
的5px
内border
,加上相对于内框的5px
内padding
,这意味着内容将具有 10 像素内10px padding
和外边框。 Here the border
is 10px
away from the content这里
border
距离内容10px
The second instance will produce a box with an outer padding
of 5px
then a 2px border
followed by 5px padding
then the content.第二个实例将生成一个外边
padding
为5px
的框,然后是2px border
,然后是5px padding
,然后是内容。 As you can see the border
has now shifted position and is 5px
away from the content如您所见,
border
现在已移动 position 并且距离内容5px
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.