php - jQuery Masonry Layout - 如何对齐图像

标签 php jquery html css

我构建了一个 jQuery 砌体布局,可以从不同类别中提取最近的帖子并将它们显示在主页上。

我不确定如何修改代码以实现两件事:

  1. 移除一些图像下方的白色小间隙,使它们彼此齐平。

  2. 对齐图像的底部行,使它们不会悬垂。我希望它们像在顶行一样形成一条整齐的直线。除了仅显示特定尺寸的图像之外,我不确定这是否可行。

这是当前布局:test-page

我希望底行始终以与下图相同的方式对齐:example layout

HTML/jQuery:

<div id="container">
<?php
$recent_posts_query = new WP_Query(array('post_type' => 'post', 
'posts_per_page' => 8, 'category_name' => 'technology', 
'Fashion/Beauty', 'Art', 'Watches/Jewellery', 'Travel',));
 while ($recent_posts_query->have_posts()){
 $recent_posts_query->the_post(); ?>
 <div class="masonryImage"><?php the_post_thumbnail();?></div>
 <?php } ?>
 </div>

 <script type="text/javascript">

    jQuery(window).load(function() {
  var container = document.querySelector('#container');
  var msnry = new Masonry( container, {
    itemSelector: '.masonryImage',
    columnWidth: '.masonryImage',                
  });  

    });


</script>

CSS:

`/* Makes two columns */
 .masonryImage {
 width: 50%;
 }

 /* Makes three columns */
 .masonryImage {
 width: 33%;
 }

 /* Makes four columns */
 .masonryImage {
 width: 25%;
 } `

最佳答案

请试试

.masonryImage img(vertical-align: middle;)

关于php - jQuery Masonry Layout - 如何对齐图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44156039/

相关文章:

html - html页面中固定侧边栏的样式

php - PHP Excel 库中的 fatal error : Class 'ZipArchive' not found in php 5. 1.6

php - Javascript - 每 X 秒运行一个 php 文件

javascript - 将数据发布到 JsonP

jquery - 无法让 boostraps jQuery 工具提示出现

html - 使用 CSS 隐藏内联 div

javascript - 如何使用 Laravel 代码作为 Ajax 响应

php - RSA加密: Create a cipher text in PHP and decrypt it in Javascript

php - Codeigniter Controller 也没有加载 View 错误消息

javascript - 电话间隙 : function not getting called