V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Can I use?
http://caniuse.com/
Less
http://lesscss.org
Cool Libraries
Bootstrap from Twitter
Jetstrap
aglsv
V2EX  ›  CSS

在 sass 中怎么通过 if 判断父元素属性来设置字号的

  •  
  •   aglsv · 2021-08-18 16:37:04 +08:00 · 980 次点击
    这是一个创建于 954 天前的主题,其中的信息可能已经有所发展或是发生改变。
            $typeset: 'card'
            $exercise-type: 'Choise'
            &[style]
              display: block
            > div.shade-btn
              display: flex
              > div
                display: flex
                position: absolute
                top: -26px
                z-index: 3
                > span
                  height: 26px
                  padding: 3px 5px
                  cursor: pointer
                  @if(&exercise-type == 'Choise')
                    font-size: 12px !important
                  @else
                    font-size: 14px !important
    
    

    这是我写的,我想通过判断 span 的上上级的 div 的 typeset 和 exercise-type 属性来设置 span 标签的字体大小,但是按照我这么写的话他不管属性对不对字号都是 12,想问问大佬们这个该怎么写啊,我这个是第一次接触 sass

    1 条回复    2021-08-18 19:35:59 +08:00
    crs0910
        1
    crs0910  
       2021-08-18 19:35:59 +08:00
    ```sass
    @use "sass:selector"
    @mixin if-root-is($selector)
    $current-sequences: & //.p .c
    $result: ()
    @each $sequence in $current-sequences
    // [.p, .c]
    $current: nth($sequence, -1) // .c
    $root: nth($sequence, 1) // .p
    $unify-root: selector.unify($root, $selector) // .p.x
    $result: append($unify-root, $current)

    @at-root #{$result}
    @content


    .p
    .c
    color: red
    @include if-root-is('.p12')
    color: green


    ```
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4183 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 10:12 · PVG 18:12 · LAX 03:12 · JFK 06:12
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.