这是一些 XML...
<style type="text/css">
.center:nth-of-type(1):firstchild {width: 100% !important;}
</style>
<div class="center">
<subjective_element_name>//This element's width should be set
<subjective_element_name>//This element is NOT a direct child, not set
</subjective_element_name>
</subjective_element_name>
</div>
我想强制作为 .center
元素子元素的 first 元素具有 width: 100%;
声明。我不希望它在任何其他元素上出现不止一次(.center
选择器只存在一次)。这意味着选择器应该只匹配上面的 subjective_element_name
元素。
最佳答案
.center > *:first-child {
/*rules here*/
}
关于CSS仅设置第一个元素的宽度而不考虑其元素名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22974815/