1. 理解 box-sizing功能并实例演示;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box {
width: 400px;
height: 400px;
background-color: yellow;
padding: 10px;
margin: 10px;
/* 始终保持宽高400px */
box-sizing: border-box;
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>
2. 理解相对定位与绝对定位,并实例演示他们的区别与联系
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
/* 绝对定位根据BODY来定位 脱离文档流*/
.parent {
width: 200px;
height: 200px;
background-color: yellow;
position: absolute;
top:20px;
left: 20px;
}
/* 相对定位根据自己的位置来定位 没有脱离文档流*/
.son {
width: 100px;
height: 100px;
background-color: green;
position: relative;
top: 150px;
left:150px;
}
</style>
</head>
<body>
<div class="parent">
<div class="son"></div>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
/* 绝对定位根据BODY来定位 脱离文档流*/
.parent {
width: 200px;
height: 200px;
background-color: yellow;
position: relative;
}
/* 相对定位根据自己的位置来定位 没有脱离文档流*/
/* 在实战子盒子根据父盒子来定位,子绝父相 */
.son {
width: 100px;
height: 100px;
background-color: green;
position: absolute;
top: 150px;
left:150px;
}
</style>
</head>
<body>
<div class="parent">
<div class="son"></div>
</div>
</body>
</html>