开发者

excluding a class from style

开发者 https://www.devze.com 2023-01-14 00:15 出处:网络
I\'m trying to style all html with the class called sample <div class=\"sample\"> </div> .sample{

I'm trying to style all html with the class called sample

<div class="sample">
</div>

.sample{

}

But I'm running into a situation where the class sample could be nested. In this case I want to style only the inner one. How can I tell the css to apply the style only to the inner div and not to the outer sample? Can this be done?

开发者_如何学C
<div class="sample">
   <div class="sample">
   </div>
</div>


Use the descendant selector for your ruleset:

.sample .sample

If you want to maintain the style on your outer div, then I'd suggest giving it another class, like

.something .sample

Using the same class for all the elements on a page is highly discouraged.


You could use Child Selectors:

div>.sample {}

or:

div.sample>.sample {}
0

精彩评论

暂无评论...
验证码 换一张
取 消