2014-05-18 169 views
1

我有一个WordPress的网站(你可以看到在duncanhill.com.au问题)网格元素没有正确对齐

如果你看的网站,前3个属性框中正确对齐,但是第四和第五做一些奇怪的东西。

的代码看起来是这样的:

HTML:

<div id="grid-gallery" class="grid-gallery"> 
<section class="grid-wrap"> 
    <ul class="grid"> 
     <li class="grid-sizer"></li><!-- for Masonry column width --> 

     <?php if (have_posts()) : while (have_posts()) : the_post(); ?> 
      <a href="<?php the_permalink(); ?>"> 
      <li> 

       <figure> 
        <div class="figimg"><?php the_post_thumbnail(); ?></div> 
        <figcaption><h3 class="figtitle"><?php the_title(); ?></h3><p class="price"><?php the_subtitle(); ?></p><p class="figdesc"><?php the_excerpt(); ?></p></figcaption> 
       </figure> 

      </li> 
      </a> 
     <?php endwhile; else: ?> 
      <p><?php _e('Sorry, no posts matched your criteria.'); ?></p> 
     <?php endif; ?> 
    </ul> 
</section><!-- // grid-wrap --> 

CSS:

/* General style */ 
.grid-gallery ul { 
    list-style: none; 
    margin: 0; 
    padding: 0; 
} 

.grid-gallery figure { 
    margin: 0; 
} 

.grid-gallery figure img/*.figimg*/ { 
    display: block; 
    /*width: 100%; 
    height: 100%;*/ 
    /*height: 210px;*/ 
    border-top-right-radius: 5px; 
    border-top-left-radius:5px; 
} 

.grid-gallery figcaption h3 { 
    margin: 0; 
    padding: 0 0 0.5em; 
} 

.grid-gallery figcaption p { 
    margin: 0; 
} 

/* Grid style */ 
.grid-wrap { 
    max-width: 69em; 
    margin: 0 auto; 
    padding: 0 1em 1.875em; 
} 

.grid { 
    margin: 0 auto; 
} 

.grid li { 
    width: 33%; 
    float: left; 
    cursor: pointer; 
} 

.grid figure { 
    padding: 15px; 
    -webkit-transition: opacity 0.2s; 
    transition: opacity 0.2s; 
} 

.grid li:hover figure { 
    opacity: 0.7; 
} 

.grid figcaption { 
font-family: 'lato'; 
font-weight: 300; 
color: #000000; 

padding: 25px; 
border-left-style: solid; 
border-right-style: solid; 
border-bottom-style: solid; 
border-width: 2px; 
border-color: #4B91F0; 
border-bottom-left-radius:5px; 
border-bottom-right-radius:5px; 
} 

.figtitle{ 
font-family: 'lato'; 
font-weight: 400; 
} 

.figdesc{ 

} 

.price{ 
font-weight: 400; 
color: #E74C3C; 
} 

我真的无法工作,如何解决它! 任何帮助对齐方块将不胜感激!

感谢, 汤姆

回答

1

有你需要做的来解决这个问题两件事情,跟你张贴的HTML做第一个。

首先,在上面更改您的HTML代码,以便删除“grid-sizer”类的空列表项,并且您的循环内的锚标记包含在列表项中。它应该是这样的,而不是你目前有:

<div id="grid-gallery" class="grid-gallery"> 
<section class="grid-wrap"> 
    <ul class="grid">  
     <?php if (have_posts()) : while (have_posts()) : the_post(); ?> 
      <li> 
       <a href="<?php the_permalink(); ?>"> 
        <figure> 
         <div class="figimg"><?php the_post_thumbnail(); ?></div> 
         <figcaption><h3 class="figtitle"><?php the_title(); ?></h3><p class="price"><?php the_subtitle(); ?></p><p class="figdesc"><?php the_excerpt(); ?></p></figcaption> 
        </figure> 
       </a> 
      </li>     
     <?php endwhile; else: ?> 
      <p><?php _e('Sorry, no posts matched your criteria.'); ?></p> 
     <?php endif; ?> 
    </ul> 
</section><!-- // grid-wrap --> 

二,添加以下样式到你的CSS:

.grid :nth-child(3n+1) { 
    clear: left; 
} 
+0

(我知道我不是为了做到这一点,它可能会无论如何,但...)感谢这么多TREVOR !!!! – TomHill

+0

没问题。很高兴我能帮上忙! – trevor