【发布时间】:2018-04-14 00:20:06
【问题描述】:
我正在尝试通过使用(将其放置在页面内容部分)使砌体布局成为可能:
[gallery size="large" link="file" columns="4" ids="1,2,3"]
文档:https://codex.wordpress.org/Gallery_Shortcode
但即使这是想要的效果:
这就是不断发生的事情:
基本上,如果可以添加一些 CSS 甚至 javascript 来转换图库以做到这一点,那就太棒了。
我现在的代码是这样的:
<div class="gallery-template">
the_content();
</div>
而我的附加 css 是:
.gallery-template img{
max-width: 100%;
height: auto;
border: none !important;
}
.gallery-item{
width: 33% !important;
margin: 0;
margin-top: 0 !important;
}
这并不能完全解决新的三分之二开始时的问题,以摆脱“行”之间的padding 和margin。
当上面提到的[gallery]短代码被渲染时,它在DOM中的渲染方式是这样的:
<div class="gallery-template">
<div id="gallery-1" class="gallery">
<dl class="gallery-item">...</div>
<dl class="gallery-item">...</div>
<dl class="gallery-item">...</div>
// And so on..
</div>
</div>
而在 DOM 中渲染的 CSS 是:
#gallery-1 {
margin: auto;
}
#gallery-1 .gallery-item {
float: left;
text-align: center;
}
.gallery-item {
width: 33% !important;
margin: 0;
margin-top: 0 !important;
}
是否有人针对此类障碍实施了解决方案?
另外,我尽量避免使用外部插件。
【问题讨论】:
标签: css wordpress gallery image-gallery