[英]Use CSS Child and Last Selector on same element
我在bootstrap panel-footer
使用glyphicons有不同的链接,如下所示:
<div class="panel-footer">
<a href class="pull-right">
<span class="glyphicon glyphicon-chevron-up"></span>
</a>
<a href class="pull-right margin-right">
<span class="glyphicon glyphicon-pencil"></span>
</a>
</div>
如您所见,我需要使用我自己的margin-right
类为最后a
-child元素应用额外的margin:
.margin-right {
margin-right: 5px;
}
上面的代码可以在这个插件中找到。
由于这似乎是一种丑陋的解决方法,我考虑将CSS子选择器与:last-element
选择器结合使用来选择所需的元素并应用所需的margin-right
。 我想出的是这样的:
<div class="panel-footer">
<a href="#" class="pull-right">
<span class="glyphicon glyphicon-chevron-up"></span>
</a>
<a href="#" class="pull-right">
<span class="glyphicon glyphicon-pencil"></span>
</a>
</div>
我用以下内容替换了CSS文件中的margin-right
样式:
.panel-footer > a:last-child {
margin-right: 5px;
}
但是,这不会产生想要的结果。 正如您在此插件中看到的那样,没有margin-right
应用于所需的子元素。
如何以我想要的方式选择最后一个子元素并应用所需的margin-right
?
使用:last-of-type
伪类而不是:last-child
:
.panel-footer a:last-of-type {
margin-right: 5px;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.