Masonry layout within the loop

try this. i am not sure it would work for masonary layout or not. but it would give you an idea on how to make rows and columns within loop.

if ($news->have_posts() ) : while ($news->have_posts() ) : $news->the_post();
    //$value = $news->current_post;

    if($value % 3 == 0){
        ?>
      <div class="row">                 
        echo "<div class="col-lg-4">";

                        <div class="height <?php foreach(get_the_category() as $category) { echo $category->slug . ' ';} ?>">
                        <div class="text">
                                <h5><?php the_time('F jS, Y'); ?></h5>
                                <h4><a href=""><?php the_title(); ?></a></h4>
                            <?php the_excerpt(); ?>
                        </div>
                    </div>


    <?php 
    //$i++;
    //print($value);
}
echo "</div>";
if($value % 3 !== 0){
echo "<div class="col-lg-4">";
echo "</div">
}
endwhile; endif;