wordpress - 如何在 Wordpress 画廊中放置图像
问题描述
当我使用 Wordpress 画廊简码 [gallery columns="3" size="medium" link="none" ids="13,14,11,16,18,19"] 它显示 3 列画廊,但图像高度不要在每一行上匹配,它会在全景图像下方留下难看的空间。
我怎样才能得到它,以便每行上所有图像的高度都相同,即使它会自动裁剪掉每张图像的某些侧面?
解决方案
如果您使用默认的 wordpress 图库标记,您可以通过添加这些 css 类来覆盖显示:
我们定义了一个固定的纵横比,用于包装画廊 div 并object-fit:
用于填充框架。
在此示例中,我们使用平方比率。
.gallery {
display: flex;
flex-wrap: wrap;
margin: 3em 0 3em -0.8em;
width: 100%;
}
* {
box-sizing: border-box
}
.gallery-item{
width:33.333%;
margin:0;
padding:0.3em;
}
/* aspect ratio hack*/
.gallery-icon {
position:relative;
padding-bottom:100%;
/* use 56.25% for 16/9 ration */
}
.gallery-icon a,
.gallery-icon img
{
position: absolute;
top:0;
right:0;
bottom:0;
left:0;
height:100%;
width:100%
}
/* prevent distortions */
.gallery-icon img{
object-fit:cover;
object-position: 50%
}
<div id="gallery-1" class="gallery galleryid-716 gallery-columns-3 gallery-size-thumbnail">
<figure class="gallery-item">
<div class="gallery-icon landscape">
<img width="200" height="400" src="https://via.placeholder.com/200x400" class="attachment-thumbnail size-thumbnail" alt="thumb" >
</div>
</figure>
<figure class="gallery-item">
<div class="gallery-icon landscape">
<img width="300" height="400" src="https://via.placeholder.com/200x100" class="attachment-thumbnail size-thumbnail" alt="thumb" >
</div>
</figure>
<figure class="gallery-item">
<div class="gallery-icon landscape">
<img width="200" height="400" src="https://via.placeholder.com/400x100" class="attachment-thumbnail size-thumbnail" alt="thumb" >
</div>
</figure>
<figure class="gallery-item">
<div class="gallery-icon landscape">
<img width="200" height="400" src="https://via.placeholder.com/200" class="attachment-thumbnail size-thumbnail" alt="thumb" >
</div>
</figure>
</div>
您也可以使用 css 属性aspect-ratio:
,但它仍未得到广泛支持。
推荐阅读
- javascript - 计数输入数 onchange
- python - 如何将 Python 转义字符与 MatLab 命令结合起来?
- algorithm - 整数到字符的转换
- ajax - 有没有人在没有捆绑包的情况下在 Symfony 4 中使用 Select2 + ajax?
- r-markdown - rmarkdown::render() 无法生成 pdf,但 rstudio 'knitr' 按钮有效
- dockerhub - 由于访问被拒绝,无人机推送到 Dockerhub 失败
- python - 括号对方法和“自我”变量的影响
- sql-server - SQL Server 2017 中不存在登录名和用户,那么为什么在 T-SQL 中会出现?
- azure - 内部应用服务环境中其他应用的名称解析
- android - 错误:无法解决:androidx.legacy:legacy-support-v4