css - 列表项的面包屑选择器,旁边有一个列表项

标签 css sass css-selectors

我创建了一个面包屑,您可以在此处查看代码 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;
            }
        }
    }
}
}

最佳答案

就像我之前说的,li + lili:first-child + li 是一样的(你可以像 & + li 如果你愿意,当然可以在你的 li 里面)。这是我的解决方案 - 我更改了选择器并将所有内容左对齐。

.breadcrumb
{
    width: auto;
    margin: 0;
    padding: 0;
    list-style: none;
    border-bottom: 1px solid grey;
    background-color: lightgray;  // watch out it's lightgray not 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;
                }
            }
            &.breadcrumb--active //changed
            {
                background-color: white;
                &:after
                {
                    border-left: 30px solid grey;
                    z-index: 1;
                }
            }
        }
    }
    li + li //changed
    {
        a
        {

            &:after
            {
                position: absolute;
                top: 0;
                left: 0; //changed
                display: block;
                content: "";
                border-top: 29px solid transparent;
                border-left: 30px solid lightgray;
                border-bottom: 29px solid transparent;
                border-right: 10px solid transparent;
                z-index: 1; //changed
            }
            &:before
            {
                position: absolute;
                top: 0;
                left: -1px; //changed
                display: block;
                content: "";
                border-top: 29px solid transparent;
                border-left: 30px solid white; //changed
                border-bottom: 29px solid transparent;
                border-right: 10px solid transparent;
                z-index: 2; //changed
            }

        }
    }
}

Jsfiddle result

关于css - 列表项的面包屑选择器,旁边有一个列表项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25643884/

相关文章:

javascript - 在悬停 css 上隐藏一个不是直接子元素的元素

jQuery:尝试编写我的第一个插件,如何将选择器传递给我的函数?

sass - 当我使用 Ruby 2.0 升级到 Mavericks 时,Codekit 无法与 Compass/Zurb Scss 编译器一起工作

css - 将时间戳添加到已编译的 sass/scss

css - 具有相似背景图像名称的多个 div

CSS 选择器,如果前一个元素有不同类名的子元素

jquery - css 选择器不是最后一个子元素不工作(需要纯 css 解决方案)

javascript - 一次点击打开 2 个页面,但不是同时打开

javascript - 粘性 div 脚本在 chrome 中不起作用

javascript - if语句javascript中的div