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

2021-08-18 16:37:04 +08:00
 aglsv
        $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

1022 次点击
所在节点    CSS
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


```

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/796580

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX