CSS::列表项上的last-child [英] CSS: :last-child on list item

查看:107
本文介绍了CSS::列表项上的last-child的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果ul包含具有多个类的li项,是否可以使用以下方法获取特定类的最后一个项:last-child?



 < ul class =test> 
< li class ='one>
< li class =one>
< li class =one>
< li class =two>
< li class =two>
< / ul>

我想添加一些样式到最后一个有类one的li

  ul.test li.one:last-child 


解决方案

这不可能





您唯一的选择是向该元素添加特定的类名,或者使用JavaScript添加这个类名。


If a ul has li items with multiple classes, is it possible to get the last item of a specific class using :last-child?

For example, consider following:

<ul class="test">
    <li class="one">
    <li class="one">
    <li class="one">
    <li class="two">
    <li class="two">
</ul>

I want to add some style to the last li having class "one" (ie. third in the list).

I tried following and it does not work.

ul.test li.one:last-child 

解决方案

That's not possible yet.

  • :last-child selects the last child, regardless of the tag name, etc.
  • The possible alternative, :last-of-type selects the last occurrence of a tag. It ignores the class name, etc.

Your only option is to add a specific class name to that element, or use JavaScript to add this class name.

这篇关于CSS::列表项上的last-child的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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