当使用自动高度与浮动其不工作,但当删除浮动其工作罚款。怎么能修好?
有一个带自动高度的DIV(aboutus),里面是另一个带左浮动的DIV(aboutus title p),但是内容是溢出的,DIV里面的所有内容怎么能带自动高度呢?
http://jsfiddle.net/haeb0q8d/1/

.aboutus {
	position: relative;
	z-index: 2;
	width: 100%;
	height: auto;
	background: #333333;
}

.aboutus-title div h1{
	text-align: center;
	text-transform: uppercase;
	font-size: 24px;
	padding-top: 80px;
	color: #fcd803;
}

.aboutus-title hr {
	margin:  0 auto;
	border: 0;
    height: 1px;
    background: #333;
    margin-top: 30px;
    width: 60px;
}

.aboutus-detail {
	width: 100%;
}

.aboutus-detail p{
	text-align: center;
	color: #fcd803;
	line-height: 25px;
	font-size: 17px;
	margin-bottom: 30px;
	padding-right: 30px;
	padding-left: 30px;
    float: left;
}

<div class="aboutus" id="aboutus">
  <div class="aboutus-title">
    <div><h1>about</h1></div>
    <hr>
    <div class="aboutus-detail">
      <p>
        We are a tight knit team of digital thinkers, designers and<br>
        developers, working together to create fresh, effective projects<br> delivered personally.
      </p>
    </div>
  </div>
</div>

最佳答案

必须用clear: both清除float。

.aboutus {
    position: relative;
    z-index: 2;
    width: 100%;
    height: auto;
    background: #333333;
}
.aboutus-title div h1 {
    text-align: center;
    text-transform: uppercase;
    font-size: 24px;
    padding-top: 80px;
    color: #fcd803;
}
.aboutus-title hr {
    margin: 0 auto;
    border: 0;
    height: 1px;
    background: #333;
    margin-top: 30px;
    width: 60px;
}
.aboutus-detail {
    width: 100%;
}
.aboutus-detail p {
    text-align: center;
    color: #fcd803;
    line-height: 25px;
    font-size: 17px;
    margin-bottom: 30px;
    padding-right: 30px;
    padding-left: 30px;
    float: left;
}
.clear {
    clear: both;
}

<div class="aboutus" id="aboutus">
    <div class="aboutus-title">
        <div>
            <h1>about</h1>
        </div>
        <hr>
        <div class="aboutus-detail">
            <p>We are a tight knit team of digital thinkers, designers and
                <br>developers, working together to create fresh, effective projects
                <br>delivered personally.</p>
        </div>
    </div>
    <div class="clear"></div>
</div>

关于html - 使用 float 自动高度,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27076177/

10-11 11:07