【发布时间】:2015-03-01 17:43:29
【问题描述】:
我一直在尝试将我当前的网站布局迁移到响应式布局,但我遇到了以下问题。在我的图片库中,我根据视口在液柱中输出缩略图。我使用媒体查询来为不同的视口实现这一点,并且始终使用宽度作为屏幕宽度的百分比。我有水平和垂直方向的缩略图。缩小效果很好,但在某些时候,当图像开始缩小时,垂直图像变得比水平图像大并且溢出它们的父元素。话虽这么说,我正在寻找一种方法来限制宽度和高度的缩小。例如,如果我使用 width: 16%;高度:0;底部填充:16%;为了实现方形元素,a 希望限制该元素内的 img 在其高度等于父元素高度时相应地缩放。
这个问题有没有唯一的 CSS 解决方案?
这是我的代码:
.photo-list {
padding: 45px 0 0 0;
width: 100%;
}
.photo-thumb {
display: inline-block;
margin: 2% 2% 2% 2%;
padding-bottom: 16%;
width: 16%;
height: 0;
vertical-align: top;
text-align: center;
background-color: grey;
}
.photo-thumb img {
max-width: 100%;
height: auto;
}
@media only screen and (max-width : 1440px),
only screen and (max-device-width : 1440px){
.photo-thumb {
width: 21%;
padding-bottom: 21%;
}
}
@media only screen and (max-width : 1080px),
only screen and (max-device-width : 1080px){
.photo-thumb {
width: 29.3333%;
padding-bottom: 29.3333%;
}
}
@media only screen and (max-width : 530px),
only screen and (max-device-width : 530px){
.photo-thumb {
width: 46%;
padding-bottom: 46%;
}
}
@media only screen and (max-width : 320px),
only screen and (max-device-width : 320px){
.photo-thumb {
width: 96%;
padding-bottom: 96%;
}
}
<ul class="photo-list clear">
<li class="photo-thumb">
<img alt="somewhere far beyond" src="http://lorempixel.com/300/200/nature/">
</li>
<li class="photo-thumb">
<img alt="into the wild" src="http://lorempixel.com/300/200/city/">
</li>
<li class="photo-thumb">
<img alt="missing summer" src="http://lorempixel.com/200/300/sports/">
</li>
<li class="photo-thumb">
<img alt="light trails" src="http://lorempixel.com/200/300/business/">
</li>
<li class="photo-thumb">
<img alt="living tree" src="http://lorempixel.com/300/200/fashion/">
</li>
<li class="photo-thumb">
<img alt="end of day" src="http://lorempixel.com/300/200/nature/">
</li>
<li class="photo-thumb">
<img alt="ray of light" src="http://lorempixel.com/200/300/city/">
</li>
</ul>
感谢任何帮助!
干杯, 杰罗姆
【问题讨论】:
-
您的 sn-p 不起作用,请使用绝对路径。
-
Horen,谢谢你,我已经修好了。
标签: css image responsive-design height liquid