<div class="test">
<p>1</p>
<span>2</span>
</div>
<div class="test">
<span>1</span>
<p>2</p>
</div>
Normally, the first child element should be. Test > P: first child or. Test > P span:first-child But if the HTML structure is not unified, such as the one I gave, I want to set the style for the first child element, how to write it? Suppose that the text color displayed by 1 is set to red color: red;
CSS can use wildcard *
So a demo of stylus is as follows
.test
*:first-child
color:red
// 亦或省略*号
.test
:first-child
color:red
Should it be like this?
Select the first element under your test test:first-child :first-child{ color:red; }