如何在父标签中使用样式强制所有标签?

时间:2019-12-30 08:00:54

标签: html css

我有一些类似html的代码:

<div style=color: green>
  <span style="color:black>Some text</span>
  <p style="color:red>Some text</p>
  <div style="color:blue>Some text</div>
</div>

我希望所有“某些文字”的父母都以红色表示,请帮忙!

3 个答案:

答案 0 :(得分:2)

欢迎来到SO Dear

  

在使用内联样式时,将*选择器与!important一起使用   !important需要对此进行覆盖。

div *{
 color: inherit !important;//parent color you can change it
}
<div style="color: green">
  <span style="color:black">Some text</span>
  <p style="color:red">Some text</p>
  <div style="color:blue">Some text</div>
</div>

您还错过了"的样式

答案 1 :(得分:0)

实现这一目标的最佳方法是创建一个类以在将来重用代码,您可以做到这一点

private fun RelativeLayout?.setWidth(i: Int) {
    val layoutParams: ViewGroup.LayoutParams? = this?.layoutParams
    layoutParams?.width = i
    this?.layoutParams = layoutParams
}

答案 2 :(得分:0)

我建议父div具有类似parent的类。 从那里,我会的。

.parent {
  color: green;
}

.parent * {
  color: inherit !important;
}
相关问题