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

标签 html css inheritance

我有一个 div,其 CSS 将所有图像设置为特定宽度。我想在这个子 div 中添加另一个子 div,但它的图像不受约束 - 可以是它们实际的大小。

我不确定如何“重置”这些子元素的宽度属性,使其不继承父元素?

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

<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???
    }

最佳答案

auto 做我做的事:

#child img {
     width: auto;
    }

关于html - 如何禁用子元素的父元素的设置宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18556321/

相关文章:

html - Z-index 不适用于父项中的子项

javascript - jQuery :not (:contains) not working with ACF select field/<select><option> tag/

css - 在 Ruby 中将外部 CSS 转换为内联 CSS 的工具?

html - 无法将表格中的复选框左对齐

c++ - 将派生类型的对象从 python 传递到期望 shared_ptr 为基类型的 C++ 函数时,Boost Python 运行时错误

java - spring数据中的多态查询

html - Bootstrap - 设计一个好的标题/导航栏

javascript - 如何将背景图片破解到 Google 图表工具的动态 (JavaScript/SVG) 图表中?

css - Bootstrap : responsive panel and image

java - 我需要在 Java 中实现继承方法吗?