dragon012100 2018-03-23 02:28
浏览 23
已采纳

3列布局 - 如何在每列中设置限制

I have a 3-column listing (data coming from api). Each page has a limit of 30. I've managed to put the listing into 3 columns.

enter image description here

I'm having some problems with my code where when it's on a bigger screen, it is no longer a 3-column layout and each column has more than 10 data.

Questions:

1) How do I make sure that this layout stays a 3-column layout even when it goes on a bigger screen?

2) How do I put a limit of 10 in each column?

php/html:

    <div id="native" class="margin-top-2x">     
         <ul>
            <?php foreach($model as $d) { ?>
             <li>
                <?php if(!empty($d['id'])): ?>
                <a href="<?php echo $this->createUrl('frontend/detailedView', array('id' => $d['id'])) ?>"><?php echo $d['title'];?> </a>
                <?php endif; ?>
                <br></li>
            <?php } ?>
        </ul>
    </div>

css:

    #native {
      -webkit-column-width: 400px;
      -moz-column-width: 400px;
      -o-column-width: 400px;
      -ms-column-width: 400px;
      column-width: 400px;

    }
    #native ul {
        list-style: none;
    }
  • 写回答

2条回答 默认 最新

  • doushansu9012 2018-03-24 00:35
    关注
    • You should draw 3 different <ul> to make sure you are getting 3 columns.
    • Move the <ul> tag outside the foreach.
    • Use if(($i % 10) == 0) where $i is the counter to limit 10 <li> in each <ul> and close the </ul> and at the same time start new one <ul> but look for if it is the last iteration (end ( $model['id'] ) == $d['id']) then do not start a new <ul>.

      See below code

      <div id="native" class="margin-top-2x">  
          <ul>
              <?php 
                 $i=1;
                 foreach ( $model as $d ) { ?>
                      <?php if ( !empty ( $d['id'] ) ): ?>
                          <li>
                              <a href="<?php echo $this->createUrl ( 'frontend/detailedView' , array( 'id' => $d['id'] ) ) ?>"><?php echo $d['title']; ?> </a>
                          </li>
                      <?php endif; ?>
                      <br>
                  <?php
                  if ( ($i % 10) == 0 ) {
                      echo "</ul>";
                      echo (end ( $model['id'] ) == $d['id']) ? "" : "<ul>";
                  }
                  $i++;
                  ?>
              <?php } ?>
      </div>
      

      The minimum Css you would need to show them in a row

      #native ul {
          display: inline-block;
      }
      
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路