Correcting teacher:Guanhui
Correction status:qualified
Teacher's comments:还行!多注意一下页面排版!
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>浮动元素的塌陷和解决方案</title>
<style>
.container{
border:3px dashed blue;
background-color: lightseagreen;
}
.item{
width: 150px;
height: 150px;
}
.item:first-of-type{
background-color:lightpink ;
}
.item:last-of-type{
background-color:lightsalmon;
}
.item:nth-of-type(2){
background-color:lightgreen ;
}
/* 当三个子元素全部浮动之后,容器container没有子元素的支持,高度塌陷, */
.item{
float:left;
}
/* 塌陷解决方案 */
/* 解决方案1. 添加一个伪元素解决-可以用,但啰嗦*/
/* .container::after{
content: "";
display: block;
clear:both;
} */
/* overflow:最简单的解决方案*/
.container{
/* overflow: hidden=overflow: auto; */
/* overflow: hidden; */
overflow: auto;
}
</style>
</head>
<body>
<div class="container">
<div class="item">浮动元素1</div>
<div class="item">浮动元素2</div>
<div class="item">浮动元素3</div>
<!-- <div class="clear"></div> -->
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>中国诗词大会:绝对定位完成三列布局</title>
<style>
/* 初始化 */
* {
margin:0;
padding:0;
box-sizing: border-box;
color:red;
font-size: 1.2rem;
}
/* 页眉样式 与内容 */
.header{
width: 1060px;
height: 500px;
margin:auto;
background:url('header.png') no-repeat center;
}
/* 页脚样式 与内容*/
.footer{
width: 1060px;
height: 130px;
margin:auto;
background:lightgreen url('footer.png') no-repeat center ;
}
/* 主体样式 */
.container{
width: 1060px;
margin: 10px auto;
background-color: #ccc;
min-height:200px;
/* 转为定位元素,作为定位父级*/
position: relative;
}
.container>.left{
width:85px;
min-height: 200px;
background-color: wheat;
background-image:url('left.png') ;
background-repeat:no-repeat;
/* 左绝对定位 */
position: absolute;
top: 0;
left:0;
}
.container>.right{
width:100px;
min-height: 200px;
background-color: wheat;
background-image:url('right.png') ;
background-repeat:no-repeat;
/* 右绝对定位 */
position: absolute;
top: 0;
right:0;
}
.container>.main{
width: 860px;
background-color: limegreen;
min-height: 200px;
background:url('main.png') no-repeat ;
/* 主体绝对定位 */
position: absolute;
left:90px;
top:0;
}
</style>
</head>
<body>
<!-- 页眉 -->
<div class="header">页眉</div>
</div>
<!-- 主体 -->
<div class="container">
<div class="left">左侧</div>
<div class="main">主体</div>
<div class="right">右侧</div>
</div>
<!-- 页脚 -->
<div class="footer">页脚</div>
</body>
</html>
}
.container>.right{
width:100px;
min-height: 200px;
background-color: wheat;
background-image:url('right.png') ;
background-repeat:no-repeat;
/* 右绝对定位 */
position: absolute;
top: 0;
right:0;
}
.container>.main{
width: 860px;
background-color: limegreen;
min-height: 200px;
background:url('main.png') no-repeat ;
/* 主体绝对定位 */
position: absolute;
left:90px;
top:0;
}
</style>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>中国诗词大会:浮动定位完成三列布局</title>
<style>
/* 初始化 */
* {
margin:0;
padding:0;
box-sizing: border-box;
color:red;
font-size: 1.2rem;
}
/* 页眉样式 与内容 */
.header{
width: 1060px;
height: 500px;
margin:auto;
background:url('header.png') no-repeat center;
}
/* 页脚样式 与内容*/
.footer{
width: 1060px;
height: 130px;
margin:auto;
background:lightgreen url('footer.png') no-repeat center ;
}
/* 主体样式 */
.container{
width: 1060px;
margin: 10px auto;
background-color: #ccc;
min-height:200px;
/* 转为定位元素,作为定位父级*/
position: relative;
}
.container>.left{
width:85px;
min-height: 200px;
/* 左浮动 */
float: left;
background: wheat url('left.png') no-repeat;
}
.container>.right{
width:100px;
min-height: 200px;
/* 右浮动 */
float: right;
background: wheat url('right.png') no-repeat;
}
.container>.main{
width: 800px;
min-height: 200px;
margin-left:40px;
background:limegreen url('main.png') no-repeat ;
/* 左浮动 */
float: left;
}
</style>
</head>
<body>
<!-- 页眉 -->
<div class="header">页眉</div>
</div>
<!-- 主体 -->
<div class="container">
<div class="left">左侧</div>
<div class="main">主体</div>
<div class="right">右侧</div>
</div>
<!-- 页脚 -->
<div class="footer">页脚</div>
</body>
</html>