html - 根据浏览器大小调整行中图像的大小

标签 html css

我有三个内联图像。它们宽 330 像素,间隔 10 像素。当在手机或任何 1,010 像素以下的窗口中显示时,图像会一个接一个地显示。我希望它们减小尺寸,以便保持内联。我试图通过在代码周围放置一个 100px 的 div 来模拟我的 jsfiddle 中的问题。这在实际代码中是不存在的。如您所见,图像不在一条线上。这里有很多关于如何执行此操作的示例,但我能找到的都没有解决多个图像的问题。有没有办法做到这一点? jsfiddle

    <style>
    .imagewrapper img {
      max-width: 90%;
      height: auto;
    }
    .box_row_f { display:inline-block; border:4px solid #5CB65C } 
    .box_row_n { display:inline-block; border:4px solid #5CB65C; margin-left:10px } 
    </style>

    <div style="width:100px">
      <div class="imagewrapper">
        <div class="box_row_f"><img src="someimage.jpg"></div>
        <div class="box_row_f"><img src="someimage.jpg"></div>
        <div class="box_row_f"><img src="someimage.jpg"></div>
      </div>
    </div>

最佳答案

我建议使用 flexbox。

.imagewrapper {
  display: flex;
}
.imagewrapper img {
  max-width: 100%;
  height: auto;
}
.box_row_f ~ .box_row_f {
  margin-left: 10px;
}
<div class="imagewrapper">
  <div class="box_row_f"><img src="//dummyimage.com/500"></div>
  <div class="box_row_f"><img src="//dummyimage.com/500"></div>
  <div class="box_row_f"><img src="//dummyimage.com/500"></div>
</div>

关于html - 根据浏览器大小调整行中图像的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41065480/

相关文章:

javascript - 从 html 表单调用 JavaScript 文件

html - 如何用html和css实现堆叠样式效果?

css - 如何创建不随背景图像跳跃的关键帧平滑连续循环?

html - 如何在内容下方设置摘要样式

html - bootstrap- 按钮链接扩展按钮

javascript - 鼠标悬停时更改文本颜色

html - CSS:格式化 block 。奇怪的高度行为或如何通过 block 内的内容调整高度

html - ASCII 字符 62 在 Superfish 菜单中显示不正确

html - 如何使用 flexbox 创建自定义表单?

html - 使用固定在屏幕两侧的 div 开发 HTML 网站