Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
例如我有这个:
<div> <a href="#">sample 1</a> <a href="#">sample 2</a> <a href="#">sample 3</a> </div>
我想用 CSS 定位第一个链接。
您可以使用第一个子选择器:
div > a:first-child { /* your css */ }
试试这个代码:
div > a:first-child{ //your css code }
div a:nth-of-type(n) { /* css */ }
其中 n 是您想要的行数..在您的情况下
div a:nth-of-type(1) { /* css */ }