Use Scss to implement css has func(使用scss实现css中has函数)

Use Scss to implement css has func(使用scss实现css中has函数)

has

has in css

The functional :has() CSS pseudo-class represents an element if any of the relative selectors that are passed as an argument match at least one element when anchored against this element. This pseudo-class presents a way of selecting a parent element or a previous sibling element with respect to a reference element by taking a relative selector list as an argument.

CSS 函数式伪类 :has() 表示一个元素,如果作为参数传递的任何相对选择器在锚定到该元素时,至少匹配一个元素。这个伪类通过把可容错相对选择器列表作为参数,提供了一种针对引用元素选择父元素或者先前的兄弟元素的方法。

<template>
    <div class="father">
        <div class="son"></div>
    </div>


</template>

<script lang="ts" setup>
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
// check sass is config success
// 检查scss是否配置成功

// css has function
$bg_color: rgba(0, 0, 0, 1);
$width: 100px;
$height: 200px;
//.container {
//  background-color: $bg_color;
//  width: $width;
//  height: $height;
//}

.father:has(.son) {
  // has role has if father has the son, this css is success
  // has函数的作用是,如果父亲有这个孩子,那么这个样式就会生效。
  background: $bg_color;
  width: $width;
  height: $height;
}


</style>

in chrome

image-20230407205925251

in 360

image-20230407210005416

.father:has(.son) {
  // has role has if father has the son, this css is success
  // has函数的作用是,如果父亲有这个孩子,那么这个样式就会生效。
  background: $bg_color;
  width: $width;
  height: $height;
}

scss

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
// check sass is config success
// 检查scss是否配置成功

// css has function
$bg_color: rgba(0, 0, 0, 1);
$width: 100px;
$height: 200px;
//.container {
//  background-color: $bg_color;
//  width: $width;
//  height: $height;
//}

@if '.scss_father .sacc_son' {
  .scss_father {
    width: 200px;
    height: 200px;
    background-color: gray;
  }
}
</style>

in chrome

image-20230407211255204

in 360

image-20230407211344518

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值