如何禁用子元素的父元素的设置宽度?

时间:2013-09-01 07:44:52

标签: html css inheritance

我有一个div,其CSS将所有图像设置为一定宽度。我想在这个中添加另一个孩子div,但是它的图像不受限制 - 无论它们实际上是什么大小。

我不确定如何'重置'这些子元素的width属性,所以它不会继承父元素?

有人知道这是怎么做到的吗?

<div id='parent'>
  <img src='image.jpg'>

  <div id='child'>
    <img src='image.jpg'>
  </div>

</div>

CSS

   #parent img {
     width: 200px;
    }

    #child img {
     width: do not inherit #parent img css???
    }

2 个答案:

答案 0 :(得分:1)

auto做我的意思:

#child img {
     width: auto;
    }

答案 1 :(得分:0)

只需添加自己的宽度。

#parent img {
     width: 200px;
    }

    #child img {
     width: 100px;
    }
相关问题