dongzhan1570 2017-06-17 03:09
浏览 45
已采纳

使用PHP for循环以Z字形顺序放置一系列图像

I'm a beginner in PHP and I'm seeking your guidance to know the possibilities of placing a sequence of images in a zigzag order using PHP loop.

The number of images received may vary each time, so the img src code is placed in a foreach loop, I currently have them display one below the other but would like to know if there is an opportunity to place them in a zigzag manner as image attached

Output I'm trying for

$j=0; 
 foreach ($data['employee'] as $teammember) {
echo $data['team']['members'][$j]['TeamRank'] . "." . $data['team']['members'][$j]['name'] ;
echo "<img src='http://yyyyyyy/employeeimage'" . $j . "'.png' />";
$j = $j + 1;
}

I'm seeking your advice in placing the name and image in zigzag form.

enter image description here

  • 写回答

1条回答 默认 最新

  • douzhe3516 2017-06-17 03:16
    关注

    This is really just CSS. Put your loop or the data from the loop inside of an element that wraps it, and on that element, apply display: flex; flex-direction: column; align-items: flex-start, and use the :nth-child() selector to change every other flex child to align-self: flex-end;

    In your loop, change this so that the text and image are wrapped in an element.

    <div class="flex">
    <?php
      $j=0; 
      foreach ($data['employee'] as $teammember) {
        echo '<div><p>' . $data['team']['members'][$j]['TeamRank'] . "." . $data['team']['members'][$j]['name'] . '</p>';
        echo "<img src='http://yyyyyyy/employeeimage'" . $j . "'.png' /></div>";
        $j = $j + 1;
      }
    ?>
    </div>
    

    And use this CSS.

    .flex {
      display: flex;
      flex-direction: column;
      align-items: flex-start;
      max-width: 50vw;
      margin: auto;
    }
    
    .flex > div:nth-child(odd) {
      align-self: flex-end;
    }
    <div class="flex">
      <!-- your php code would go here, and just output a list of images -->
      <div>
        <p>text</p>
        <img src="http://kenwheeler.github.io/slick/img/lazyfonz2.png">
      </div>      
      <div>
        <p>text</p>
        <img src="http://kenwheeler.github.io/slick/img/lazyfonz2.png">
      </div>
      <div>
        <p>text</p>
        <img src="http://kenwheeler.github.io/slick/img/lazyfonz2.png">
      </div>
      <div>
        <p>text</p>
        <img src="http://kenwheeler.github.io/slick/img/lazyfonz2.png">
      </div>
      <div>
        <p>text</p>
        <img src="http://kenwheeler.github.io/slick/img/lazyfonz2.png">
      </div>
      <div>
        <p>text</p>
        <img src="http://kenwheeler.github.io/slick/img/lazyfonz2.png">
      </div>
    </div>

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 MATLAB代码补全插值
  • ¥15 Typegoose 中如何使用 arrayFilters 筛选并更新深度嵌套的子文档数组信息
  • ¥15 前后端分离的学习疑问?
  • ¥15 stata实证代码答疑
  • ¥50 husky+jaco2实现在gazebo与rviz中联合仿真
  • ¥15 dpabi预处理报错:Error using y_ExtractROISignal (line 251)
  • ¥15 在虚拟机中配置flume,无法将slave1节点的文件采集到master节点中
  • ¥15 husky+kinova jaco2 仿真
  • ¥15 zigbee终端设备入网失败
  • ¥15 金融监管系统怎么对7+4机构进行监管的