深度选择器


项目开发过程中,经常会使用到第三方组件库的组件,以便快捷的构建功能模块。

例如;使用 Element UI 的走马灯(轮播图)组件

<el-carousel height="150px">
     <el-carousel-item v-for="item in 4" :key="item">
         <h3 class="small">{{ item }}</h3>
    </el-carousel-item>
</el-carousel>
这个时候想修改左右箭头指示器的样式或者偏移位置

查看自带的样式代码

 无论是直接使用 button 标签选择器 还是其 类名 都无法选到来修改样式

这是因为在style中使用了 less(scss) 和 scoped

这个时候就需要用到 深度选择器了

例如,修改button大小和位置,使用::v-deep

::v-deep .el-carousel__arrow--left {
  width: 50px;
  height: 50px;
  left: 100px;
  background-image: url('~@/assets/images/indeximg/left.png');
}
::v-deep .el-carousel__arrow--right {
  right: 100px;
  width: 50px;
  height: 50px;
  background-image: url('~@/assets/images/indeximg/right.png');
}
还有其它写法如 >>> 或者是 /deep/,但是这里都不起作用,所以用::v-deep

原文链接:https://blog.youkuaiyun.com/YoungMan_09/article/details/124183560

在SCSS中,可以使用深度选择器(也称为嵌套选择器)来选择嵌套层级的元素。深度选择器使用`&`符号表示当前选择器的父级。 以下是一个示例,展示了如何在SCSS中使用深度选择器: ```scss .container { background-color: #f5f5f5; .nested-element { color: #333; & > span { font-weight: bold; } } .another-nested-element { font-style: italic; &.active { color: blue; } } } ``` 在上述示例中,我们定义了一个`.container`类选择器,并在其中嵌套了两个元素的选择器:`.nested-element`和`.another-nested-element`。 使用深度选择器,我们可以在`.nested-element`的内部使用`&`来表示`.nested-element`本身,从而生成`.container .nested-element`的样式规则。同样地,我们可以在`.another-nested-element`的内部使用`&`来表示`.another-nested-element`本身,从而生成`.container .another-nested-element`的样式规则。 此外,我们还可以使用深度选择器来进行更复杂的选择。例如,在上述示例中,我们使用了`& > span`来选择`.nested-element`内部直接子元素为`<span>`的规则。 注意,深度选择器`&`只能在嵌套的选择器内部使用。它可以帮助我们编写更简洁和易读的SCSS代码,减少了重复的选择器名称。 当我们将上述SCSS代码编译成CSS时,会生成相应的选择器规则,如下所示: ```css .container { background-color: #f5f5f5; } .container .nested-element { color: #333; } .container .nested-element > span { font-weight: bold; } .container .another-nested-element { font-style: italic; } .container .another-nested-element.active { color: blue; } ``` 以上就是在SCSS中使用深度选择器的基本用法。通过嵌套选择器,我们可以更方便地编写出层级结构清晰的样式规则。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值