简体   繁体   English

CSS样式化'div'元素嵌套在其他元素的深处

[英]CSS Styling a 'div' element nested deep inside other elements

This is how the code looks: 这是代码的样子:

在此输入图像描述

And I want to a border for the highlighted element, ie <div class="Comment">...</div> , how do I style it using CSS? 我想要突出显示元素的边框,即<div class="Comment">...</div> ,如何使用CSS设置样式?

NOTE: Notice the class named 'Comment'? 注意: 请注意名为“Comment”的类? It is used in both the highlighted element and it's parent element. 它在突出显示的元素和它的父元素中都使用。 So, that's probably why this one's a bit tricky? 那么,这可能就是为什么这个有点棘手?

I tried the CSS codes below, and some others, and none worked. 我尝试了下面的CSS代码和其他一些代码,但都没有。

.DataList .Item .comment, .DataList .Comment .comment,
.DataList .FirstComment .comment, .DataList .Mine .comment {
    border:1px solid #666;
    padding:10px;
    border-radius:3px;
        -moz-border-radius:3px;
        -webkit-border-radius:3px;
}

.DataList .Item div.comment, .DataList .Comment div.comment,
.DataList .FirstComment div.comment, .DataList .Mine div.comment {
    border:1px solid #666;
    padding:10px;
    border-radius:3px;
        -moz-border-radius:3px;
        -webkit-border-radius:3px;
}

What am I doing wrong? 我究竟做错了什么? Hope someone can help me solve this small riddle. 希望有人能帮我解决这个小谜语。 Thanks. 谢谢。

first, try NOT styling with extreme specificity (adding parent/element selectors). 首先,尝试不具有极端特异性的样式(添加父/元素选择器)。 this way, you can just use .Comment - note that they ARE case sensitive. 这样,您可以使用.Comment - 请注意它们区分大小写。

if styles are overridden or you have selectors of the same name but different "context" (like you have a list item with .Comment and it's child with div with .Comment ), that's when you use higher specificity (adding the parent/element in the selector) like div.Comment , .Item .Comment 如果样式被覆盖或者你有相同的名称但不同的“上下文”的选择(例如你有一个列表项.Comment和它的孩子用DIV .Comment ),当您使用更高的特异性(添加父/元素的选择器)就像div.Comment.Item .Comment

正在使用嵌套样式 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?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 获得元素内部其他元素深处的价值 - Getting value of element which is deep inside other elements 设置div悬停动作的样式以不移动其他元素 - Styling div hover action to not move other elements 正在使用嵌套样式 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? 禁用 CSS 特定 div 中所有元素的样式? - Disable CSS Styling for all elements in specific div? 1 个 div 内有 2 个元素,我希望另一个元素与第一个元素一起缩放 - 2 elements inside 1 div, i want the other element to scale with the first one div中的绝对元素不会出现在其他元素之上 - Absolute element inside div won't appear on top of other elements 在div内添加新元素可将其他元素上下推 - Adding a new element inside div pushes other elements down and out 设置div元素内元素的格式,而不会继承CSS - Formatting of elements inside a div element without effect of inherited css 造型<p>里面的标签<div>通过使用 CSS - Styling <p> tag inside <div> by using CSS 其他 div 元素内的响应式 div 元素 - Resposive div element inside other div element
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM