【问题标题】:left aligned boxes don't stay in parent div左对齐框不会留在父 div 中
【发布时间】:2017-05-30 15:26:30
【问题描述】:

我有一些我想向左浮动的盒子,所以它们会并排对齐。但我有一个问题。如果我设置 float: left; 我得到这个: left aligned

他们跳出父 div(灰色 div)。如果我设置float: none; 我得到这个:float: none

盒子留在 div 中,div 与它们一起延伸,但它们是一个在另一个之下,我不喜欢。如何在 div 中实现左对齐框?
盒子的 CSS:

.parent {
  float: left;
  width: 200px;
  background-color: white;
  border: 1px solid rgb(230,230,230);
  margin: 10px;
}

【问题讨论】:

标签: html css


【解决方案1】:

你必须使用溢出 css 规则。在灰色框中添加以下 css 属性:

overflow:hidden;

应用此属性后,您将获得灰色框内的项目,并且它们不会落在它之外。

【讨论】:

    【解决方案2】:

    您需要在最后将<div style="clear:both"></div> 提供给内部父 div。

    <div class="parent">
        your code
        <div style="clear:both;"></div>
    </div>
    

    【讨论】:

      【解决方案3】:

      无论何时使用 float,都需要通过将 clear: both 分配给其父级来清除它

      【讨论】:

      • 当我添加 clear: both 到其父 div 时没有任何反应
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-01-08
      • 1970-01-01
      • 2017-07-02
      • 2018-10-21
      • 1970-01-01
      • 2015-02-22
      • 1970-01-01
      相关资源
      最近更新 更多