dourukeng5302 2014-01-26 15:53
浏览 32
已采纳

PHP中的PHP回声

I have a PHP script which echos in a div, which had another div inside of it. I am stumped, and I want to know how to make the second div seperate from the first one, so that one will be on one side and the other on the other side.

Here's the PHP

  echo '<div class="viewpost">';
  while ($row = mysqli_fetch_array($data)) {
  if(!empty($row['first_name'])) {
      echo '<div class="vpside">';
      echo '<p>Name:' . $row['first_name'] . '</p>';
    }
  if(!empty($row['gender'])){
    echo '<p>Gender: ' . $row['gender'] . '</p>';
    echo '</div>';
  }
  if(!empty($row['post'])) {
      echo '<p class="vpside1">Post:</p><p class="viewpost1">' . $row['post'] . '</p>';
    }
    }
  echo '</div>'; 

Here's the CSS

.vpside {
    height:100%;
    width:12%;
    display:block;
    border-right:5px solid white;
    border-bottom:5px solid white;
    border-top:5px solid white;
}

.vpside1 {
    width:10%;
    border-right:5px solid white;
    border-bottom:5px solid white;
    border-top:5px solid white;
}

.viewpost {
    margin-bottom:25px;
    background-color: #000;
    border: 5px solid white;
    border-radius:10px;
}

p.viewpost {
    background-color: #000;
}

.viewpost1 {
    border-bottom: 5px solid white;
    }
  • 写回答

1条回答 默认 最新

  • douzhuan1467 2014-01-26 16:00
    关注

    You can just end the first div before you define the other div to separate them. For example:

    <?php
      echo '<div class="viewpost">';
      echo '</div>'; //Bottom line moved here
      while ($row = mysqli_fetch_array($data)) {
      if(!empty($row['first_name'])) {
          echo '<div class="vpside">';
          echo '<p>Name:' . $row['first_name'] . '</p>';
        }
      if(!empty($row['gender'])){
        echo '<p>Gender: ' . $row['gender'] . '</p>';
        echo '</div>';
      }
      if(!empty($row['post'])) {
          echo '<p class="vpside1">Post:</p><p class="viewpost1">' . $row['post'] . '</p>';
        }
        }
    ?>
    

    Or if you wanted to keep the <p> inside the one div:

    <?php
      while ($row = mysqli_fetch_array($data)) {
      if(!empty($row['first_name'])) {
          echo '<div class="vpside">';
          echo '<p>Name:' . $row['first_name'] . '</p>';
        }
      if(!empty($row['gender'])){
        echo '<p>Gender: ' . $row['gender'] . '</p>';
        echo '</div>';
      }
      echo '<div class="viewpost">';
      if(!empty($row['post'])) {
          echo '<p class="vpside1">Post:</p><p class="viewpost1">' . $row['post'] . '</p>';
        }
        echo '</div>';
        }
    ?>
    

    Then, if you want them to be side by side, add display: inline-block to each div:

    .vpside {
        height:100%;
        width:12%;
        display: inline-block; /*changed from display: block*/
        border-right:5px solid white;
        border-bottom:5px solid white;
        border-top:5px solid white;
    }
    
    .vpside1 {
        width:10%;
        border-right:5px solid white;
        border-bottom:5px solid white;
        border-top:5px solid white;
    }
    
    .viewpost {
        margin-bottom:25px;
        background-color: #000;
        border: 5px solid white;
        border-radius:10px;
        display: inline-block; /*added*/
    }
    
    p.viewpost {
        background-color: #000;
    }
    
    .viewpost1 {
        border-bottom: 5px solid white;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 iOS 自定义输入法-第三方输入法
  • ¥15 很想要一个很好的答案或提示
  • ¥15 扫描项目中发现AndroidOS.Agent、Android/SmsThief.LI!tr
  • ¥15 怀疑手机被监控,请问怎么解决和防止
  • ¥15 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译