我有以下 html 结构。
<ul>
<script id="agendaTmpl" type="text/x-jquery-tmpl">
<li class="arrow boundElement" style="height:40px;" onclick="GoToPage('session.html?session_id=${agenda_id}');">
</li>
</script>
<li class="arrow boundElement" style="height:40px;" onclick="GoToPage('session.html? session_id=2');"> test</li>
<li class="arrow boundElement" style="height:40px;" onclick="GoToPage('session.html? session_id=2');"> test</li>
</ul>
我需要将类应用于列表的第一行。
无法删除脚本标签,因为它是结构的模板。
我尝试使用 ul > li:first-child
但它不起作用。它仅在 li 是 ul 的第一个子节点时有效,即如果脚本标签不存在。
请建议我一种将样式应用于 ul 的第一行的方法。
注意:我不允许在第一行添加新类。
最佳答案
尝试使用 first-of-type
代替:
ul > li:first-of-type
这是一个 CSS3 选择器 - 因此在旧版浏览器中不完全支持。查看@Boltclock 的回答以获得更好的跨浏览器支持
关于html - 第一个列表项的CSS选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10580371/