
scss 中消除子元素继承父元素属性的方法
在 Scss 中,子元素通常会继承父元素的样式属性。这通常是很方便的,但有时候也可能是不希望的,例如当子元素需要覆盖父元素的样式时。
要消除这种继承,可以使用将子元素的样式属性设为 initial,例如:
.parent {
background-color: red;
}
.child {
background-color: initial;
}这样,子元素 child 就不会继承父元素 parent 的 background-color 属性,而是使用它的默认值。
在你的示例中,黄色盒子继承了红色盒子的 position:absolute 属性,导致黄色盒子覆盖了蓝色盒子的一部分。为了解决这个问题,可以在黄色盒子中将 position 属性设为 initial,如下所示:
立即学习“前端免费学习笔记(深入)”;
#action {
position: absolute;
bottom: 100px;
left: 0;
height: 150px;
width: 200px;
background-color: red;
.hide {
position: initial;
width: 40px;
height: 100%;
background-color: orange;
}
.panel {
height: 100%;
width: 156px;
background-color: rgb(46, 187, 209)
}
}这样做之后,黄色盒子就不会再覆盖蓝色盒子,因为它的 position 属性不再继承父元素的值。
以上就是Scss 中如何消除子元素继承父元素属性?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号