【问题标题】:Two Column Repeater Field Advanced Custom Fields两列重复字段高级自定义字段
【发布时间】:2019-09-26 14:56:50
【问题描述】:

我是 ACF 的新手,想使用转发器字段来创建两列行。它按我想要的方式运行(两个偶数,减半的列)。我希望每一列都以与另一列相同的高度开始,因此我设置了高度。但是我想确保我使用的是最佳实践……我是如何按照您建议的方式编写的?我觉得可能有更好的方法。

提前谢谢你。

PHP

<div class="bg-white">
     <div class="dib mw9 center">

      <?php

      if( have_rows('faq') ):
          while ( have_rows('faq') ) : the_row(); ?>

            <div class="parent">
              <h4><?php the_sub_field('question'); ?></h4>
              <p><?php the_sub_field('question_answer'); ?></p>
            </div>

          <?php endwhile;
          else :
          endif;
      ?>

      </div>
 </div>

CSS

.parent {
    display: inline-block;
    height: 240px;
    width: 50%; 
    float: left;
    padding: 48px 24px;
}

【问题讨论】:

    标签: php css wordpress advanced-custom-fields


    【解决方案1】:

    如果您能够向包装 div (class="dib ...") 添加一个额外的类,我们将其称为 '.parent-wrapper',您可以简单地使用以下代码:

    .parent-wrapper {
        display: flex;
        flex-wrap: wrap;
    }
    
    .parent {
        flex: 50%;
        padding: 48px 24px;
    }
    

    不需要高度,因为 flex 会处理它。在这里,您与内容长度无关。所以即使是很长的答案也会被正确格式化。

    希望对你有帮助:)

    【讨论】:

    • @ZachPeach 很高兴听到这个消息:) 如果答案合适,请点击“接受”。谢谢!
    猜你喜欢
    • 2020-04-26
    • 2017-12-16
    • 2018-08-06
    • 1970-01-01
    • 2018-08-26
    • 2013-07-14
    • 2013-11-25
    • 1970-01-01
    • 2020-01-22
    相关资源
    最近更新 更多