我正在处理几个设置为内联块和溢出的图像:滚动。
目前所有图像都在同一个类="父容器"但只有水平图像是缩放的,当屏幕改变大小时,我的垂直图像保持相同的大小。
我正在寻找所有我的图像进行扩展。
我的HTML
<div class="parent-container">
<div class="container">
<img src="1.jpg" alt="" class="image" style="width:100%">
</div>
<div class="container">
<img src="2.jpg" alt="" class="image" style="width:100%">
</div>
<div class="container">
<img src="3.jpg" alt="" class="image" style="width:100%">
</div>
<div class="container">
<img src="4.jpg" alt="" class="image" style="width:100%">
</div>
<div class="container">
<img src="5.jpg" alt="" class="image" style="width:100%">
</div>
</div>
我的CSS
.parent-container {
width: 100%;
max-width: 1175px;
height: auto;
padding: auto;
overflow: scroll;
overflow-y: hidden;
margin-left: 35px;
margin-top: 5px;
white-space: nowrap;
display: inline-block;
}
.container {
position: relative;
display: inline-block;
padding-right: 15px;
padding-left: 15px;
}
.image {
opacity: 1;
display: inline-block;
width: 100%;
height: auto;
transition: .5s ease;
backface-visibility: hidden;
padding-right: 15px;
}
.parent-container .container .image {
width: auto\9; /* IE8 */
}
谢谢!
答案 0 :(得分:0)
您可以尝试将object-fit: cover;
添加到图片中,并使用固定的height
。这应该缩放你的图像。
.parent-container {
width: 100%;
max-width: 1175px;
height: auto;
padding: auto;
overflow: scroll;
overflow-y: hidden;
margin-left: 35px;
margin-top: 5px;
white-space: nowrap;
display: inline-block;
}
.container {
position: relative;
display: inline-block;
padding-right: 15px;
padding-left: 15px;
}
.image {
opacity: 1;
display: inline-block;
width: 100%;
height: 100px;
transition: .5s ease;
backface-visibility: hidden;
object-fit: cover;
}
<div class="parent-container">
<div class="container">
<img src="https://dummyimage.com/100x100/000/fff" alt="" class="image" style="width:100%">
</div>
<div class="container">
<img src="https://dummyimage.com/200x150/000/fff" alt="" class="image" style="width:100%">
</div>
<div class="container">
<img src="https://dummyimage.com/200x100/000/fff" alt="" class="image" style="width:100%">
</div>
</div>