首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >到达DIV容器末端后中断行

到达DIV容器末端后中断行
EN

Stack Overflow用户
提问于 2017-02-01 09:53:14
回答 3查看 1K关注 0票数 3

下面是从数据库中获取图像的代码。它一直在破坏DIVoverflows。我想要的是当图像到达DIV的末尾时,它应该中断并开始一条新的行。但我不知道如何做到这一点。请帮帮我伙计们。

代码

代码语言:javascript
复制
<div class="inline-flex">
    <?php while($faf = $prooq->fetch()){ extract($faf); ?>
       <div class="image-container"> <img class="myThumb" id="myImg" src="proofs/<?php echo $pr_image; ?>" alt="" width="160" height="100">
          <div class="image-text">shreyansh ($8.75)<br>
          <span><?php echo date('jS M, Y (h:i a)', strtotime($pr_uptime)); ?></span></div>
       </div>
       <div id="myModal" class="modal"> <span class="close">&times;</span> <img class="modal-content" id="modalImg">
          <div id="caption"></div>
       </div>
    <?php } ?>
</div>

CSS

代码语言:javascript
复制
.image-container {
    width: 163px;
    height: 100px;
    padding: 0px 0px 65px 0px;
    font-size: 12px;
    text-align: center;
    font-family: Verdana, Arial, Helvetica, sans-serif;
    margin-right: 13px;
}

.image-text {
    margin-top: 5px;
}
.image-text span {
    color: #ddd;
    font-size: 9px;
}
.inline-flex {
    width: 100%;
    display: inline-flex;
}
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2017-02-04 14:12:53

我找到了解决方案的答案。在带有属性.proof-container的类position: relative;中添加了一个额外的DIV,并封装了其中的所有元素,并向.image-container添加了一个属性float: left;。就这样。以下是代码:

CSS:

代码语言:javascript
复制
.image-container {
    width: 197px;
    height: 120px;
    padding: 0px 0px 65px 0px;
    font-size: 12px;
    text-align: center;
    font-family: Verdana, Arial, Helvetica, sans-serif;
    margin-right: 10px;
    float: left;
}

.proof-container {
    width: 100%;
    position: relative;
}

HTML:

代码语言:javascript
复制
<div class="proof-container">
        <?php while($faf = $prooq->fetch()){ extract($faf); ?>
        <div class="image-container">
          <img class="myThumb" id="myImg" src="proofs/<?php echo $pr_image; ?>" alt="" width="160" height="100">
          <div class="image-text"><?php echo $mem_uname; ?> ($8.75)<br>
            <span><?php echo date('jS M, Y (h:i a)', strtotime($pr_uptime)); ?></span></div>
        </div>
        <div id="myModal" class="modal"> <span class="close">&times;</span> <img class="modal-content" id="modalImg">
          <div id="caption"></div>
        </div>
        <?php } ?>
      </div>
票数 0
EN

Stack Overflow用户

发布于 2017-02-01 10:33:20

尝试使用display:table

代码语言:javascript
复制
.inline-flex {
     width: 100%;
     display: table;
}
票数 0
EN

Stack Overflow用户

发布于 2017-02-01 11:13:18

您需要将display: inline-block; float: left;设置为.image-container

代码语言:javascript
复制
.image-container {
    width: 163px;
    height: 120px;
    padding: 0px 0px 65px 0px;
    font-size: 12px;
    text-align: center;
    font-family: Verdana, Arial, Helvetica, sans-serif;
    margin-right: 13px;
    display: inline-block;
    float: left;
}

.image-text {
    margin-top: 5px;
}
.image-text span {
    color: #ddd;
    font-size: 9px;
}
.inline-flex {
    width: 100%;
}
代码语言:javascript
复制
<div class="inline-flex">
   <div class="image-container"> <img class="myThumb" id="myImg" src="http://lorempixel.com/output/nature-q-c-200-200-3.jpg" alt="" width="160" height="100">
          <div class="image-text">shreyansh ($8.75)<br>
          <span>date('jS M, Y (h:i a)', strtotime($pr_uptime));</span></div>
       </div>
       </div>
   <div class="image-container"> <img class="myThumb" id="myImg" src="http://lorempixel.com/output/nature-q-c-200-200-3.jpg" alt="" width="160" height="100">
          <div class="image-text">shreyansh ($8.75)<br>
          <span>date('jS M, Y (h:i a)', strtotime($pr_uptime));</span></div>
       </div>
   <div class="image-container"> <img class="myThumb" id="myImg" src="http://lorempixel.com/output/nature-q-c-200-200-3.jpg" alt="" width="160" height="100">
          <div class="image-text">shreyansh ($8.75)<br>
          <span>date('jS M, Y (h:i a)', strtotime($pr_uptime));</span></div>
       </div>
   <div class="image-container"> <img class="myThumb" id="myImg" src="http://lorempixel.com/output/nature-q-c-200-200-3.jpg" alt="" width="160" height="100">
          <div class="image-text">shreyansh ($8.75)<br>
          <span>date('jS M, Y (h:i a)', strtotime($pr_uptime));</span></div>
       </div>
   <div class="image-container"> <img class="myThumb" id="myImg" src="http://lorempixel.com/output/nature-q-c-200-200-3.jpg" alt="" width="160" height="100">
          <div class="image-text">shreyansh ($8.75)<br>
          <span>date('jS M, Y (h:i a)', strtotime($pr_uptime));</span></div>
       </div>
   <div class="image-container"> <img class="myThumb" id="myImg" src="http://lorempixel.com/output/nature-q-c-200-200-3.jpg" alt="" width="160" height="100">
          <div class="image-text">shreyansh ($8.75)<br>
          <span>date('jS M, Y (h:i a)', strtotime($pr_uptime));</span></div>
       </div>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41976637

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档