我在使div行居中时遇到问题,我有3个来自wordpress的帖子,相当于该行内的3列,但是在我添加了许多CSS属性使其居中之后,居然没有居中。我也在使用wordpress。
这是我的代码:
<div class="row center-block">
<?php while ( $offerBlog->have_posts() ) : $offerBlog->the_post(); ?>
<div class="col-md-4 ">
<img src="<?php the_field('offer_image') ?>">
<br>
<br>
<h4><?php the_field('offer_title') ?></h4>
<?php the_field('offer_description') ?>
</div>
<?php endwhile; ?>
</div>
这是我的CSS:
.col-md-4 {
width:15%;
margin:0 2.5%;
text-align: center
}
.center-block {
margin-left:auto;
margin-right:auto;
display:center;
}
试试这个:
在此处查看演示
CSS:
.center-block {
display: flex;
flex-direction: row;
justify-content: center;
}
希望对您有所帮助
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句