html - 当前元素和子元素的 CSS 样式
问题描述
有没有办法同时设置当前元素和子元素的 CSS 样式?
这适用于当前元素。
.test
{
color: red;
height: 100%;
border-radius: 12px;
}
这将适用于类 .test 的后代子元素。
.test *
{
color: red;
height: 100%;
border-radius: 12px;
}
如何选择当前和后代子元素?
解决方案
由于没有关于您的具体项目结构的更多信息......
只需留在您的代码中,您就可以执行以下操作:
.test,
.test *
{
color: red;
height: 100%;
border-radius: 12px;
}
注意: using*
可能根本不是最佳实践,因为它设置了每个元素的样式(在这种情况下,所有子元素甚至是第二、第三...级别以下.test
)。为避免这种情况,您可以这样做:
.test,
.test > *
{
... your code
}
// or better more specific
// use the tag-name of the direct childs
// in this case I take 'div' as example
.test,
.test > div {
... your code
}
推荐阅读
- r - 如何调整条形组之间的空间和条形的宽度,并在 ggplot2 中使用一些时髦的代码将其中两个缝合在一起?
- list - 使用 Cryptollist 问题实现 GIFT-COFB 算法
- python - 如何使用 R 或 Python 或 Excel 拆分数据,以便它们在每 n 行之后水平分布?
- javascript - 多选js附加getJson不显示任何选项
- maven - Maven JavaDoc --enable-preview
- python - 使用 Python,如何拆分多个分隔符并在输出列表中只保留一个?
- javascript - 如何将事件侦听器添加到多个按钮,每个按钮修改数据的不同部分
- http-headers - ServiceWorker 无法在刷新时加载带有 CSP 异常的谷歌字体
- python - 样式 CheckboxSelectMultiple 表单域。姜戈
- sql - 有没有办法在视图中使用动态 SQL?