div不会扩展浮动内容的高度

时间:2017-03-15 17:06:36

标签: html css

这个问题已被问到一堆,我看了他们(貌似)。我有一个div有一些浮动内容,不会扩展到内容的大小。我添加了clear:both(字面意思是每个可能的行,它有效果,但没有解决它),我已经尝试了overflow:hiddenoverflow:auto的每个排列这里的每一个元素。我还尝试将div更改为跨度。

无论我做什么,如果你让窗户变得足够瘦,最终按钮会低于div的区域。为什么以及如何解决?

JSFiddle

.confirmation-modal {
    z-index: 1; /* Sit on top */
    width: 100%; /* Full width */
    height: 4rem;
    max-height:18rem;
    overflow: auto;
    text-align: center;
    border-radius:5px;
    
}


.confirmation-raised-panel{
    background-color: #ffed83;
    padding: 0px;
    text-align: center;
    height: 4rem; /* Full height */
    max-height:18rem;    
        overflow: auto;
}

.buttons{
  float:right;
}

.confirmation-message {
    overflow: auto;
  margin: 20px 0 0 30px;
  font-size: 1.2rem;
  font-weight: 400;
  float:left;
}

.clear{
  clear:both;
}
<div class="confirmation-modal">
    <div class="confirmation-raised-panel">
        <div class="confirmation-message">
            This is a big message that takes up a bunch of space.  Yes indeed.  Do you like it?
        </div>
        <div>
            <div class="buttons">        
                <button>Yes, I'm Sure</button>
                <button>Cancel</button>
            </div>
                <br class="clear"/>    
        </div>
    </div>
</div>

2 个答案:

答案 0 :(得分:0)

嗯,外部两个容器中有height: 4rem; - 这可以防止它们变得更高。将其删除或制作min-height,即可完成设置:

.confirmation-modal {
  z-index: 1;
  /* Sit on top */
  width: 100%;
  /* Full width */
  min-height: 4rem;
  max-height: 18rem;
  overflow: auto;
  text-align: center;
  border-radius: 5px;
}

.confirmation-raised-panel {
  background-color: #ffed83;
  padding: 0px;
  text-align: center;
  min-height: 4rem;
  max-height: 18rem;
  overflow: auto;
}

.buttons {
  float: right;
}

.confirmation-message {
  overflow: auto;
  margin: 20px 0 0 30px;
  font-size: 1.2rem;
  font-weight: 400;
  float: left;
}

.clear {
  clear: both;
}
<div class="confirmation-modal">
  <div class="confirmation-raised-panel">
    <div class="confirmation-message">
      This is a big message that takes up a bunch of space. Yes indeed. Do you like it?
    </div>
    <div>
      <div class="buttons">
        <button>Yes, I'm Sure</button>
        <button>Cancel</button>
      </div>
      <br class="clear" />
    </div>
  </div>
</div>

答案 1 :(得分:0)

你的模态(("image.url"))有一个固定的高度,他无法展开。

height: 4rem
.confirmation-modal {
  width: 100%;
  text-align: center;
  border-radius: 5px;
  background-color: #ffed83;
  overflow: hidden;
}

.confirmation-message {
  margin: 1rem;
  font-size: 1.2rem;
  font-weight: bold;
}

.buttons{
  float: right;
  margin: 0 1rem 1rem;
}

相关问题