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