【发布时间】:2014-09-03 23:27:09
【问题描述】:
我创建了一个面包屑,您可以在此处查看代码http://jsfiddle.net/zgx5qcsx/
我需要一个 CSS 选择器来将 &:after &:before 提供给除了最后一个 li 之外的所有内容,但我无法弄清楚 - 目前我笨拙地得到了:
li:first-child,
li:first-child + li
这并不理想,因为随着更多步骤的添加,我必须修改!
任何建议将不胜感激
.breadcrumb
{
width: auto;
margin: 0;
padding: 0;
list-style: none;
border-bottom: 1px solid grey;
background-color: light-grey;
li
{
float: left;
margin: 0;
width: 33.33333333%;
a
{
&:link, &:visited
{
position: relative;
width: auto;
display: block;
// border-right: 1px solid grey;
@include x-rem(padding, 20px 20px 20px 50px);
text-decoration: none;
span
{
background-color: orange;
color: white;
}
}
}
}
li:first-child,
li:first-child + li
{
a
{
&:after
{
position: absolute;
top: 0;
right: -40px;
display: block;
content: "";
border-top: 29px solid transparent;
border-left: 30px solid light-grey;
border-bottom: 29px solid transparent;
border-right: 10px solid transparent;
z-index: 2;
}
&:before
{
position: absolute;
top: 0;
right: -41px;
display: block;
content: "";
border-top: 29px solid transparent;
border-left: 30px solid grey;
border-bottom: 29px solid transparent;
border-right: 10px solid transparent;
z-index: 1;
}
&.breadcrumb--active
{
background-color: white;
&:after
{
border-left: 30px solid white;
}
}
}
}
}
【问题讨论】:
-
您可以使用
last-child并将display设置为none。或者你可以使用li:not(:last-child) -
如果该网站是公开的,我还建议您查看 caniuse.com/#feat=css-sel3 并确保 CSS 最有可能适用于目标受众。
-
for info li + li 和 li:first-child + li 一样,如果你把它放在左边而不是右边,你可以把你的风格放在第一个之后
标签: css sass css-selectors