0

我一直在试图弄清楚如何在 wordpress 中修复我的画廊简码。基本上,目标是用户可以在短代码中放置任何大小的图像,并且在查看时不会看起来拉伸或扭曲。

这是应该的样子

http://i255.photobucket.com/albums/hh140/testament1234/Thumb_zpsf57e544b.jpg

这是我在编码时想出的。

http://s255.photobucket.com/user/testament1234/media/thumbnail_zpsd95f993d.jpg.html?sort=3&o=0

如果您注意到第一张图片底部缺少 5 像素的边距。第二张和第三张图片没有触及 div 的底部。

这是function.ph的代码

//Gallery Shortcode 2
function short_gallery($atts, $content = null) {
extract(shortcode_atts(array(), $atts));
return '<div class=" gallery_box"><div class="inner_gallery"><a class="fancybox"  href="'.$content.'"><img src="'.$content.'"/></a></div></div>';
}
add_shortcode("gallery", "short_gallery"); 

这是我的样式代码。

.gallery_box{background-color:#E8ECEF; float:left; margin:0px 20px 10px 0px; width:250px; height:200px; overflow:hidden }

.inner_gallery{margin:10px; margin:5px}
.inner_gallery img{max-width:100%; }

研究了几个小时我如何才能达到我想要的结果。只要图像适合容器并且质量不失真,就可以裁剪图像

4

2 回答 2

0

更改您的样式以匹配这些:

-将边框属性添加到gallery_box

.gallery_box{
background-color:#E8ECEF; 
float:left; 
margin:0px 20px 10px 0px; 
width:250px;     
height:200px; 
overflow:hidden; 
border:5px solid #E8ECEF; 
}

-删除“.inner_gallery{margin:10px; margin:5px}”类

-将 .inner_gallery img 更改为:

.inner_gallery img{
  max-width : 400px;
  max-height : 400px;
}

这是一个快速的捷径解决方案,但它可以完成工作。只要你对裁剪没问题。

于 2013-07-09T15:09:46.477 回答
0

我的建议是将图像设置为其容器的背景图像(或 img 标签的背景图像,并将 src 设置为空白图像以进行适当的缩放):

<figure>
    <img src="BLANK_IMAGE_WITH_YOUR_TARGET_SIZE" style="background-image:url('URL')" alt="My Image" />
</figure>

然后将背景大小设置为覆盖:

figure { width:250px; border:solid 5px #666; margin:0 20px 10px 0; }
figure img { width:100%; background-size:cover; background-position:center center; background-repeat:no-repeat; }
于 2013-07-10T02:44:31.513 回答