我正在拉取所有不同尺寸的图像,但希望它们是由基于百分比宽度的内嵌块列表项构成的网格内的正方形。我建立的页面是:http://ohmydrifter.com/category/inspiration/,我的HTML是:可能使用overflow:hidden将img裁剪为正方形,但将比率保留在基于百分比的宽度容器中?
<ul id="inspiration-grid">
<li class="mix">
<div class="grid-thumbnail">
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_post_thumbnail(); ?></a>
</div><!-- end grid-thumbnail -->
<h4><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h4>
</li> <!-- .mix -->
</ul> <!-- end #inspiration-grid -->
我的CSS是:
.grid-thumbnail {
overflow: hidden;
width: 184px;
height: 184px;
}
它的工作原理,但我想要做的是有.grid缩略图的div是百分比宽度。在将图像裁剪为正方形的同时可以做到这一点吗?
检查也'背景大小:cover' https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Background_and_Borders/Scaling_background_images – LGSon