从数据库中提取时背景图像是否重叠?

时间:2017-06-04 15:24:37

标签: php html css

我从正在运行的数据库中提取图像,但所有图像都是重叠的。我想逐个显示所有图像。你能帮帮我吗?

    .img {
    position: relative;
    float: left;
    width:  300px;
    height: 300px;
    background-position: 50% 50%;
    background-repeat:   no-repeat;
    background-size:     cover;
}

   <?php if ($result_related_products->num_rows > 0) { // output data of each row                                   
          while($row = $result_related_products->fetch_assoc()) {
                      $p_img=$row['p_img'];
                      ?>
                        <div class="img" style="background-image: url('admin/assets/img/products/<?php echo $p_img; ?>')">
                             <?php } 
                              } 
           else { echo "0 results"; } ?>

2 个答案:

答案 0 :(得分:1)

您必须关闭 DIV

</div>

(在你的while循环中)

答案 1 :(得分:1)

您忘了关闭div

更改此

<div class="img" style="background-image: url('admin/assets/img/products/<?php echo $p_img; ?>')">

为此(请参阅</div>)行尾

<div class="img" style="background-image: url('admin/assets/img/products/<?php echo $p_img; ?>')"></div>