css继承,隐藏根元素

标签 css inheritance

我有这样的东西:

    <ul class='yellow'>
      <li>item 1</li>
      <li>item 2</li>
      <li>item 3</li>
    <ul>

    <ul class='yellow'>
      <li>item 1</li>
      <li>item 2</li>
      <li>item 3</li>
    <ul>

我为 ul 中的 eatch li 元素设置了背景。我认为最好的方法是使用ul {background: Yellow}li {background:inherit}。继承有效,但我不知道如何隐藏 ul 容器的背景...我尝试使用 display: inlinewidth: 0px 和默认溢出来解决它,但它不起作用。

最佳答案

不要设置 <ul> 的背景颜色。仅将其设置为<li>是你的 child <ul class='yellow'> .

ul.yellow li{
  background-color: #ff0;
}

关于css继承,隐藏根元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13455478/

相关文章:

html - 针对 :after element on hover

javascript - 这是我应该使用 Javascript 原型(prototype)继承看到的行为吗?

c++ - 我需要通过基类静态变量访问派生类成员

html - Flexbox 填充剩余窗口高度不起作用

css - 如何为这两个图像禁用换行符

css - 文件上传未在模态中正确呈现文本

c# - 如何避免从基类构造函数调用虚方法

HTML,需要有关使用网格设计 "1 page"网站的建议

postgresql - 错误 :"Key ... is not present in table"

c++ - 继承问题 : Using header files and default constructor of the base class in the derived class