#mainContent .container{
background-image:url("/images/index_33.jpg");
background-repeat:no-repeat;
padding-left:85px;
margin-top:10px;
}
如何仅将这些规则应用于具有类容器的第一个 div?
最佳答案
要“将这些规则应用到带有类容器的第一个 div”,您需要更具体一些 div.container
,然后使用 first-child
伪类。
#mainContent div.container:first-child {
background-image:url("/images/index_33.jpg");
background-repeat:no-repeat;
padding-left:85px;
margin-top:10px;
}
来自 w3scools.com :
The :first-child pseudo-class adds a style to an element that is the first child of another element.
关于css - 也许只应用一次规则的子选择器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4770441/