批改状态:合格
老师批语:写得非常棒呢
实例演示如何消除子元素浮动造成父元素高度折叠的影响
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>实例演示如何消除子元素浮动造成父元素高度折叠的影响</title>
<style>
.box {
width: 500px;
background-color: blue;
border: 1px dashed #ff0000;
}
.box1 {
width: 200px;
height: 200px;
background-color: aquamarine;
float: left;
}
</style>
</head>
<body>
<div class="box">
<div class="box1">子元素浮动</div>
</div>
</body>
</html>点击 "运行实例" 按钮查看在线实例
解决办法高度折叠的办法就是给父元素加上overflow: hidden;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>实例演示如何消除子元素浮动造成父元素高度折叠的影响</title>
<style>
.box {
width: 500px;
background-color: blue;
border: 1px dashed #ff0000;
/*解决办法高度折叠的办法就是给父元素加上overflow: hidden;*/
overflow: hidden;
}
.box1 {
width: 200px;
height: 200px;
background-color: aquamarine;
float: left;
}
</style>
</head>
<body>
<div class="box">
<div class="box1">子元素浮动</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">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>实例演示三列布局的实现原理绝对定位实现</title>
<style>
.pre {
width: 1000px;
height: auto;
margin: 0 auto;
}
.header {
width: 1000px;
height: 50px;
background-color: blueviolet;
}
.main {
width: 1000px;
min-height: 800px;
background-color: bisque;
position: relative;
}
.footer {
width: 1000px;
height: 60px;
background-color: aquamarine;
}
.left {
width: 150px;
height: 800px;
background-color: #369852;
}
.middle {
background-color: antiquewhite;
width: 700px;
height: 800px;
}
.right {
width: 150px;
height: 800px;
background-color: brown;
}
/*绝对定位实现三列布局*/
.left {
position: absolute;
left: 0;
top: 0;
}
.right {
position: absolute;
top: 0;
right: 0;
}
.middle {
margin: 0 150px;
}
</style>
</head>
<body>
<div class="pre">
<div class="header">头部</div>
<div class="main">
<div class="left">左侧</div>
<div class="middle">中间</div>
<div class="right">右侧</div>
</div>
<div class="footer">底部</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">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>实例演示三列布局的实现原理浮动定位实现</title>
<style>
.pre {
width: 1000px;
height: auto;
margin: 0 auto;
}
.header {
width: 1000px;
height: 50px;
background-color: blueviolet;
}
.main {
width: 1000px;
min-height: 800px;
background-color: bisque;
overflow: hidden;
}
.footer {
width: 1000px;
height: 60px;
background-color: aquamarine;
}
.left {
width: 150px;
height: 800px;
background-color: #369852;
}
.middle {
background-color: antiquewhite;
width: 700px;
height: 800px;
}
.right {
width: 150px;
height: 800px;
background-color: brown;
}
/*浮动定位实现*/
.left {
float: left;
}
.right {
float: right;
}
.middle {
width: 700px;
float: left;
margin: 0 auto;
}
</style>
</head>
<body>
<div class="pre">
<div class="header">头部</div>
<div class="main">
<div class="left">左侧浮动定位实现</div>
<div class="middle">中间浮动定位实现</div>
<div class="right">右侧浮动定位实现</div>
</div>
<div class="footer">底部</div>
</div>
</body>
</html点击 "运行实例" 按钮查看在线实例
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号