html - CSS 选择器选择 div 内的所有 img 标签,而不考虑子级别

标签 html css css-selectors

我想选择 div 中的所有 img 标签,以便可以对其应用通用的 CSS

我不知道 img 标签可以达到什么水平

<div class="my_div">
   <div>
      <p>
         <img src="x"/>
      </p>
      <img src="y"/>
      <p>
        <a>
           <img src="z"/>
        </a>
     </p>
   </div>
</div>

而且这个结构可以改变,因为它本质上是动态的,唯一不变的是顶级 div my_div。我想在所有 img 上应用 css 作为:

{
  max-width:100% !important;
}

有什么想法可以实现吗?

最佳答案

试试这个

.my_div img
{
   max-width:100%;
}

如果这不适用然后使用 !important 像这样

.my_div img
{
   max-width:100% !important;
}

关于html - CSS 选择器选择 div 内的所有 img 标签,而不考虑子级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46300989/

相关文章:

javascript - chrome div 随机去高度 0px

html - 文本框内右侧的按钮(这是最好的方法吗?)

html - border-collapse : separate 样式行或列而不是单元格

css - 为什么 "text-align: center"在 Chrome "Inspect element"中被删除?

html - 可以在 css 边距值中使用负像素还是我应该做其他事情?

html - div ID 中的多个无序列表

css - 带有 Jquery 的自动 ajax 选择器

css - 仅选择元素的直接子元素,而不考虑标签名称

javascript - 使用 jQuery 替换输入文本

html - 如何更改 Jekyll's kramdown 中脚注的格式?