html - 与 UL & Flex CSS 混淆,2 行,2 列,共 4 项

标签 html css wordpress flexbox

我正在尝试将我的 WordPress 帖子设置为 2 宽和 2 行。

我创造了弗兰肯斯坦!

我怎样才能让它像这张图片。

enter image description here

Click me for Dev Website

PHP/HTML

    <ul class="svcta_listing_related_posts_ul">
    <li class="svcta_listing_related_posts_li">
        <?php foreach( $posts as $post): ?>
        <?php setup_postdata($post); ?>
        <?php the_post_thumbnail('listing_post_thumbnail'); ?> 
            <div class="svcta_listing_related_posts_link"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div>
    </li>
        <?php endforeach; ?>
</ul>

CSS

.svcta_listing_related_posts_ul {
  list-style: none;
  margin: 0px;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
}

.svcta_listing_related_posts_li {
margin-right: 75px;
}

最佳答案

您可以使用 css 网格来做到这一点。检查下面的代码片段

.svcta_listing_related_posts_ul {
  list-style: none;
  margin: 0px;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  display: grid;
  grid-template-columns: auto auto;
}

.svcta_listing_related_posts_li {
  margin-right: 75px;
}
<ul class="svcta_listing_related_posts_ul">
  <li class="svcta_listing_related_posts_li">
    <?php foreach( $posts as $post): ?>
    <?php setup_postdata($post); ?>
    <?php the_post_thumbnail('listing_post_thumbnail'); ?>
    <div class="svcta_listing_related_posts_link">
      <a href="<?php the_permalink(); ?>">
        <?php the_title(); ?>test
      </a>
    </div>
  </li>
 <li class="svcta_listing_related_posts_li">
    <?php foreach( $posts as $post): ?>
    <?php setup_postdata($post); ?>
    <?php the_post_thumbnail('listing_post_thumbnail'); ?>
    <div class="svcta_listing_related_posts_link">
      <a href="<?php the_permalink(); ?>">
        <?php the_title(); ?>test
      </a>
    </div>
  </li>
 <li class="svcta_listing_related_posts_li">
    <?php foreach( $posts as $post): ?>
    <?php setup_postdata($post); ?>
    <?php the_post_thumbnail('listing_post_thumbnail'); ?>
    <div class="svcta_listing_related_posts_link">
      <a href="<?php the_permalink(); ?>">
        <?php the_title(); ?>test
      </a>
    </div>
  </li>
 <li class="svcta_listing_related_posts_li">
    <?php foreach( $posts as $post): ?>
    <?php setup_postdata($post); ?>
    <?php the_post_thumbnail('listing_post_thumbnail'); ?>
    <div class="svcta_listing_related_posts_link">
      <a href="<?php the_permalink(); ?>">
        <?php the_title(); ?>test
      </a>
    </div>
  </li>

  <?php endforeach; ?>
</ul>

下面突出显示的部分应该用 li 包裹 enter image description here

关于html - 与 UL & Flex CSS 混淆,2 行,2 列,共 4 项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52961368/

相关文章:

html - 是否可以向 Bootstrap 事件选项卡添加箭头?

javascript - 如何在 jQuery 中获取前面的 `&lt;input type="文本">` 的值?

javascript - 如何关闭 Accordion 菜单的打开部分?

javascript - 从另一个页面单击链接时打开特定选项卡

css - Woocommerce Storefront 为主页上的产品类别添加悬停效果

html - 限制上传的文件类型,即只显示 mp3

html - 表溢出父元素

html - 消除网站底部的空白

wordpress - 评级显示数字而不是星星

wordpress - WooCommerce Hook 在购物车和结帐页面上的输出问题