在vue中使用less 在style标签加入scoped属性 伪元素边框无法显示
<style lang="less" scoped>
:root {
--borderColor: #03a9f3;
}
.border-radius {
position: relative;
width: 140px;
height: 64px;
margin: auto;
border: 1px solid #03a9f3;
cursor: pointer;
&::before,
&::after {
content: "";
position: absolute;
width: 20px;
height: 20px;
transition: 0.3s ease-in-out;
}
&::before {
top: -5px;
left: -5px;
border-top: 1px solid var(--borderColor);
border-left: 1px solid var(--borderColor);
}
&::after {
right: -5px;
bottom: -5px;
border-bottom: 1px solid var(--borderColor);
border-right: 1px solid var(--borderColor);
}
&:hover::before,
&:hover::after {
width: calc(100% + 7px);
height: calc(100% + 15px);
}
}
</style>
<div class="border-radius"></div>
这是不加scoped属性的效果
这是加上scoped属性的效果
加上
scoped
表示该样式就只能作用于当前的组件,无法作用于:root
选择器匹配的根元素了。