设置列表中前10个项目的样式 [英] Styling the first 10 items in a list

查看:42
本文介绍了设置列表中前10个项目的样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以使用li:nth-​​child之类的样式来设置列表中的前十项吗?

Can something like li:nth-child be used to style the first ten items in a list?

<ol>
  <li>item 1</li>
  <li>item 2</li>
  <li>item 3</li>
  <li>item 4</li>
  <li>item 5</li>
  <li>item 6</li>
  <li>item 7</li>
  <li>item 8</li>
  <li>item 9</li>
  <li>item 10</li>
  <li>item 11</li>
  <li>item 12</li>
</ol>

所以1到10会很有趣,而11和12会很正常.如果可能的话,我宁愿不使用课程.

so 1 to 10 will be fancy and 11 and 12 will be normal. I'd rather not use a class if possible.

推荐答案

第n个子示例:

:nth-child(-n+10)

此功能可在此处使用:链接.

this in works here: link.

有关了解此内容的更多信息,请访问网站.

more on understanding this check out this site.

我想如果您想要IE支持,我真的不能做得更漂亮.至少我不知道这种廉价的技巧.

I guess if you want IE support, i can't really make this any prettier. Atleast I don't know how with this cheap hack.

ul>li + li + li + li + li + li + li + li + li + li + li{
    text-align: center; /*makes everything after 10 centered*/

}​

http://jsfiddle.net/TzLqZ/作为上述示例

这是IE方式,前10个为中心,后2个为正常: http://jsfiddle.net/TzLqZ/3/

Here is the IE way with first 10 being center and the last 2 being normal: http://jsfiddle.net/TzLqZ/3/

ol>li{
    text-align: center;
    color: blue;
}
ol>li+li+li+li+li+li+li+li+li+li+li
{
    text-align: left;
    color: red;
}

这篇关于设置列表中前10个项目的样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆