.firstRow div:nth-child(2) {
background: green;
width: 40px;
height: 100px;
border: 1px solid black;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
<div class="firstRow">
<div>
<p>test.</p>
<p>test 2.</p>
</div>
</div>
您要定位的子元素是 p
元素,而不是 div
元素:
.firstRow p:nth-child(2) {
background: green;
width: 40px;
height: 100px;
border: 1px solid black;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
<div class="firstRow">
<div>
<p>test.</p>
<p>test 2.</p>
</div>
</div>
我是一名优秀的程序员,十分优秀!