如何使用CSS将样式添加到前两个列表元素 [英] how can style be added to the first 2 list elements using CSS
本文介绍了如何使用CSS将样式添加到前两个列表元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个以下格式的列表,如何使用CSS(应该在IE8中工作)添加样式到前两个列表元素:
I have a list of the following format, how can I add style to the first 2 list elements using CSS (should work in IE8):
<ul id="list1" style="margin-left:-20%;font-weight:bold" >
<li class="xyz"> Element1 </li>
<li class="xyz"> Element2 </li>
<li class="xyz"> Element3 </li>
</ul>
推荐答案
尝试这种方式
#list1 li:first-child
{
//styles//
}
#list1 li:first-child+li
{
//styles//
}
这篇关于如何使用CSS将样式添加到前两个列表元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文