老师请问下高度的问题
ABOUT区域下半区图文交错显示代码如下:
html:
<div class="bottom">
<ul>
<li class="img">
<img src="images/b1.jpg" alt="">
</li>
<li class="desc">
<div class="library">
<h2>Library</h2>
<p class="desc1">
Lorem Ipsum is simply dummy text of the printing and typesetting industry
</p>
<p class="desc2">
Lorem Ipsum has been the industry's standard dummy<br>text ever since the 1500s,when an unknown printer<br>took a gallery of type and scrambled it to make a type specrimen book.
</p>
</div>
<div class="explore">
<input type="button" value="EXPLORE">
</div>
</li>
<li class="img">
<img src="images/b2.jpg" alt="">
</li>
<li class="desc">
<div class="computer">
<h2>Computer Lab</h2>
<p class="desc1">
Lorem Ipsum is simply dummy text of the printing and typesetting industry
</p>
<p class="desc2">
Lorem Ipsum has been the industry's standard dummy<br>text ever since the 1500s,when an unknown printer<br>took a gallery of type and scrambled it to make a type specrimen book.
</p>
</div>
<div class="explore">
<input type="button" value="EXPLORE">
</div>
</li>
<li class="desc">
<div class="hall">
<h>Conference Hall</h1>
<p class="desc1">
Lorem Ipsum is simply dummy text of the printing and typesetting industry
</p>
<p class="desc2">
Lorem Ipsum has been the industry's standard dummy<br>text ever since the 1500s,when an unknown printer<br>took a gallery of type and scrambled it to make a type specrimen book.
</p>
</div>
<div class="explore">
<input type="button" value="EXPLORE">
</div>
</li>
<li class="img">
<img src="images/b3.jpg" alt="">
</li>
<li class="desc">
<div class="ground">
<h2>Play Ground</h2>
<p class="desc1">
Lorem Ipsum is simply dummy text of the printing and typesetting industry
</p>
<p class="desc2">
Lorem Ipsum has been the industry's standard dummy<br>text ever since the 1500s,when an unknown printer<br>took a gallery of type and scrambled it to make a type specrimen book.
</p>
</div>
<div class="explore">
<input type="button" value="EXPLORE">
</div>
</li>
<li class="img">
<img src="images/b4.jpg" alt="">
</li>
</ul>
</div>
</div>
CSS:
.about .bottom{
margin-top: 80px;
overflow: hidden;
zoom:1;
}
.about .bottom>ul>li{
list-style: none;
float: left;
width: 25%;
/*height: 380px;*/
}
.about .bottom>ul>li>img{
width: 100%;
height: 100%;
}
.about .bottom ul .desc{
background-color: #07cbc9;
padding:20px 30px 0 30px;
box-sizing: border-box;
color: #fff;
overflow: hidden;
}
.about .bottom ul .desc h2{
font-weight: normal;
}
.about .bottom ul .desc .desc1{
margin-top: 20px;
margin-bottom: 20px;
font-size: 15px;
}
.about .bottom ul .desc .desc2{
font-size: 12px;
}
/*EXPLORE父div填满li剩余高度*/
.about .bottom ul .desc .explore{
height: 184px;
width: 100%;
position: relative;
/*background-color: yellow;*/
}
/*input修改成块级元素设置绝对定位使其垂直水平居中*/
.about .bottom ul .desc .explore input{
width: 103px;
height: 45px;
font-size: 15px;
background-color: black;
color: white;
border:none;
display: block;
position: absolute;
top:0;
bottom: 0;
left: 0;
right: 0;
margin:auto;
}
.about .bottom ul .desc input:hover{
background-color: transparent;
border:2px solid black;
cursor: pointer;
}
我的问题是,为什么li在没有设置高度的情况下排列会混乱,而且是在图文交错的情况下,我试了全是图片或者全是文字都不会乱,请问老师这是什么原理呢?
正在回答
同学你好,这里我们可以这样理解:浮动的框可以向左或向右移动,直到它的外边缘碰到包含框或另一个浮动框的边框为止。设置了浮动后的元素,就是脱离了标准文档流,漂浮在页面上方,浮动后的元素按照浮动的顺序与方向依次展示在页面上。
当出现高度不一致时,浮动元素会找到最近的浮动的框进行显示,则第二行第一个元素,是左浮动找到的最近的浮动框,是第一行第三个元素(因高度从而找到的框),所以第二行第一个元素在浏览器最右边进行展示。因已经到最右侧,所以第二行其他元素,从浏览器的最左侧进行展示。
祝学习愉快!
- 参与学习 人
- 提交作业 676 份
- 解答问题 9666 个
本阶段将从前端网页搭建入手,到Java Web基础,前后端结合助你完成Java Web小白的蜕变!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星