html - 连续两个可变大小的 img,它们的中间在屏幕上居中,如果太大则水平滚动

标签 html css

我基本上想显示 2 张图像并排显示,并以它们在屏幕中心接触的方式对齐(与图像大小无关)。我能够通过固定定位完成它,但在这种情况下,如果图像对于屏幕“它们的”各自的一侧来说太大,则不会滚动。

HTML:

<div class="left">
    <img src="xyz.jpg"/>
</div>
<div class="right">
    <img src="abc.jpg"/>
</div>

CSS:

.left {
   position: fixed;
   right: calc(50% + 10px); 
   width: auto;
}
.right {
   position: fixed;
   left: calc(50% + 10px); 
   width: auto;
}

FIDDLE

知道如何通过水平滚动获得相同的行为吗?我相信这不能用 position: fixed 来完成。还有别的办法吗? 谢谢1

最佳答案

您可以使用 float 和宽度的一半 (50%)。由于正文的溢出默认值为自动(滚动),因此滚动会自动出现。

试试这个,看看它是否是你想要的。

<div class="left">
  <img src="http://i.imgur.com/afd65O1.png" />
</div>
<div class="right">
  <img src="http://i.imgur.com/WTuWgFvl.jpg" />
</div>

和 CSS

.left,
.right {
  float: left;
  width: 50%;
}

Fiddle

关于html - 连续两个可变大小的 img,它们的中间在屏幕上居中,如果太大则水平滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36477089/

相关文章:

html - IE 中 div 中未对齐的垂直分页器

html - 表变量列大小

html - 在移动 View 上左右交换 div

css - 如何在不指定父元素高度的情况下显示子元素 ('.cylon' )

javascript - 动画图像的CSS

html - 在 Node.js 和 Html 之间传递数据

css - html中的垂直表格标题

html - 图标没有并排放置

php - 如何缓存网页中的静态html元素?

javascript - 如何使用jquery替换html标签