溢出的图像;t符合纵横比
Overflowing images that don't conform to aspect ratio
我有一个基本的缩略图列表,它可以包含不同纵横比的图像,如图所示:
演示1
问题是,由于纵横比的混乱,它看起来有点不整洁。
理想情况下,我希望不符合特定纵横比的图像保持居中,并根据其最短边缘优雅地溢出。
我已经设法使其适用于高图像,但不适用于宽图像,如本小提琴所示:
演示2
这是标记和CSS:
CSS
.galleryArea {
background: rgba(0,0,0,0.7);
display:flex;
padding: 10px;
}
.galleryArea .imageWrapper {
position: relative;
width: calc(10% - 2px);
padding-top: 8%;
margin: 0 1px;
}
.galleryArea .imagePosition {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
.galleryArea .imagePosition img {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
max-width: 100%;
width: 100%;
}
HTML
<div class="galleryArea">
<div class="imageWrapper">
<div class="imagePosition">
<img src="http://placehold.it/300x300">
</div>
</div>
<div class="imageWrapper">
<div class="imagePosition">
<img src="http://placehold.it/300x300">
</div>
</div>
<div class="imageWrapper">
<div class="imagePosition">
<img src="http://placehold.it/150x400">
</div>
</div>
<div class="imageWrapper">
<div class="imagePosition">
<img src="http://placehold.it/300x300">
</div>
</div>
<div class="imageWrapper">
<div class="imagePosition">
<img src="http://placehold.it/300x100">
</div>
</div>
<div class="imageWrapper">
<div class="imagePosition">
<img src="http://placehold.it/300x300">
</div>
</div>
<div class="imageWrapper">
<div class="imagePosition">
<img src="http://placehold.it/300x300">
</div>
</div>
<div class="imageWrapper">
<div class="imagePosition">
<img src="http://placehold.it/300x300">
</div>
</div>
<div class="imageWrapper">
<div class="imagePosition">
<img src="http://placehold.it/300x300">
</div>
</div>
<div class="imageWrapper">
<div class="imagePosition">
<img src="http://placehold.it/300x300">
</div>
</div>
</div>
理想情况下,这将是一个纯CSS解决方案,但如果不可能,我不介意使用JS(jQuery)来实现结果。
非常感谢
Chris
编辑
为了更好地说明我的意图,这里有一个使用jQuery的例子。这是否只能使用CSS
实现?
演示3
您可以使用transform: translate(-50%, -50%);
对只有CSS的图像进行信箱处理,.imagePosition
图像上只有overflow:hidden
的宽度将垂直和水平居中对齐。
.galleryArea .imagePosition img {
width: auto;
max-width: inherit;
position: absolute;
left: 50%;
top: 50%;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
-o-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
display: block;
}
小提琴示例-http://jsfiddle.net/v6q426bp/11/
您也可以将height:100%
或width:100%
添加到图像中,以进一步限制布局。
使用height:100%
-与具有12(无法添加超过2个链接)的上面或下面的链接相同
宽度width:100%
-http://jsfiddle.net/v6q426bp/13/
相关文章:
- 如何使用url加载程序在webpack中导入多个图像
- nodejs-expressjs上传图像并显示它们
- 如何检测是否有溢出
- 使用JSP从服务器检索和显示图像
- 角度:在ng重复上切换图像
- 画廊图像未显示
- Phonegap-(安卓/iphone)多个图像的图像库出现问题
- 图像宽度和高度,无拉伸或溢出
- 将两个图像合并为一个,并使用javascript进行溢出隐藏
- 当溢出-x 设置为隐藏时处理可变高度图像的最佳方法是什么?
- 绘制图像时JavaScript堆栈溢出
- HTML2Canvas将溢出的内容转换为图像
- 处理溢出的负位置图像:自动
- 溢出的图像;t符合纵横比
- 如何删除覆盖图像查看器的溢出(滚动条)
- Jquery滑块;使容器透明,我如何隐藏图像溢出
- 如何显示溢出:隐藏的内容使用jQuery / JS当用户点击一个图像
- 放大后的Jquery中心图像溢出:自动容器
- 关于制作带有垂直溢出图像的响应式 jquery 轮播的建议
- 图库图像溢出到左边