html - 两张图片并排响应

标签 html css

我正在尝试并排放置两个图像并使它们响应。现在的问题是,第二张图片首先换行,然后根据浏览器的大小使用react。 我希望它们保持在同一行(水平)上并自动更改它们的大小并在某个点换行(这部分不是问题)......

html:

<div id="wrapper">
  <div id="outer">
      <div class="itemwrapper">
        <img src="item2.jpg" alt="bag" />
      </div>
      <div class="itemwrapper">
        <img src="item3.jpg" alt="pen" />
      </div>
  </div>
</div>

CSS:

#wrapper {
  max-width: 1050px;
  margin: 60px auto 60px auto;
  background-color: #DDD
}

.itemwrapper {
  display: inline;
}

img {
  max-width: 100%;
  height: auto;
}

最佳答案

使用显示表并排设置并保持并排和响应。

display: table; with table-layout: fixed; 将为 display: table-cell; 的子元素创建流畅的布局

这不仅可以使它们保持相同的宽度,还可以使容器保持相同的高度。

vertical-align: top; 将使它们与顶部对齐,或者您可以将垂直位置更改为 middlebottom 加上一些其他。

任何问题都可以解决。

#wrapper {
  max-width: 1050px;
  margin: 60px auto 60px auto;
  background-color: #DDD
}
#outer {
  display: table;
  width: 100%;
  table-layout: fixed;
}
.itemwrapper {
  display: table-cell;
  vertical-align: top;
  width: 100%;
}
img {
  max-width: 100%;
  height: auto;
}
<div id="wrapper">
  <div id="outer">
    <div class="itemwrapper">
      <img src="item2.jpg" alt="bag" />
    </div>
    <div class="itemwrapper">
      <img src="item3.jpg" alt="pen" />
    </div>
  </div>
</div>

关于html - 两张图片并排响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37575577/

相关文章:

Javascript 不适用于 firefox 和 IE,但适用于 chrome

javascript - Ajax 响应 xml 页面获取标题元素不起作用

javascript - 阻止具有特定 url 的脚本

javascript - 使用 Bootstrap Popover 阻止父操作

javascript - 向下滚动时可调整大小停止工作

html - 表单下拉列表位于固定标题上方

html - 使用 CSS 进行输入限制或验证

php - 如何仅显示当前列表项并隐藏其他项

css - 垂直移动页面和高分辨率

html - 溢出和滚动在 HTML 页面上无法正常工作