【问题标题】:Horizontal list menu: Calculated equal % width水平列表菜单:计算等于 % 宽度
【发布时间】:2014-06-23 18:42:04
【问题描述】:

我对 sass/compass 很陌生,现在我正在尝试使用 mixins。下面的示例显示了一个简单的带状样式水平菜单的代码,它已经继承了 @include Horizo​​ntal-list mixin,并与 compass 捆绑在一起。

这个静态菜单有四个列表项,因此我将 li 宽度设置为 25%

我的问题。 Compass 是否有一种方法可以为具有未定义项目数的动态菜单中的列表项计算相等的百分比宽度值?

类似,总 li/100 = x% li 宽度

    @mixin ribbon-menu {

        ul {
            padding: 0;
        }
        li {
            width: 25%;  
            border-right: 1px solid $white;
            text-align: center;
        }
        li.last { 
            border-left: 0;
        }
        li.leaf {
            padding: 0;
        }
        a {
            display: block;
            text-decoration: none;
            padding: 10px;
            color: $white;
        }
        a:link, a:visited {
            background: $black;
        }
        a:active, a:hover, a:focus {
            background: $red;
        }
}

【问题讨论】:

    标签: compass-sass


    【解决方案1】:

    希望这会对你有所帮助。

    http://lea.verou.me/2011/01/styling-children-based-on-their-number-with-css3/

    @for $i from 1 through 4 {
       li:first-child:nth-last-child(#{$i}),
       li:first-child:nth-last-child(#{$i}) ~ li {
       width: 100% / $i }
     } 
    

    【讨论】:

    • 谢谢。我希望 sass 可能足够聪明,知道有 4 个项目,而不是需要这个指定。但这仍然是一个很好的节省时间。
    • 在玩过这个之后,似乎如果指定的项目数大于实际数量,则生成相等的百分比值。正是我想要的。
    猜你喜欢
    • 2017-09-09
    • 2023-03-15
    • 1970-01-01
    • 2011-04-20
    • 2011-09-06
    • 2016-07-26
    • 2023-03-05
    • 2015-11-01
    • 1970-01-01
    相关资源
    最近更新 更多