简体   繁体   English

正在使用嵌套样式 css<div> 总是可交换的?</div><div id="text_translate"><p> 我试图了解您使用 div 标签定义 css 样式的顺序是否重要。</p><p> 是: </p><p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"><div class="snippet-code"><pre class="snippet-code-html lang-html prettyprint-override"> &lt;div class="some styling 1"&gt; &lt;div class="some styling 2"&gt; Some content &lt;/div&gt; &lt;/div&gt;</pre></div></div><p></p><p> 始终与以下内容相同: </p><p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"><div class="snippet-code"><pre class="snippet-code-html lang-html prettyprint-override"> &lt;div class="some styling 2"&gt; &lt;div class="some styling 1"&gt; Some content &lt;/div&gt; &lt;/div&gt;</pre></div></div><p></p><p> ?</p><p> 谢谢!</p></div>

[英]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 1padding: 5px; on some styling 2some 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.第一个实例将在外框上生成一个带有边框的框,并且内容将具有相对于padding5pxborder ,加上相对于内框的5pxpadding ,这意味着内容将具有 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.第二个实例将生成一个外边padding5px的框,然后是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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM