<!--
宽高自适应:
自适应:元素能够根据窗口发生变化,或者元素根据内容而变化
宽度自适应:元素不设置宽度就是宽度自适应
元素默认宽:width:auto;
思考:元素宽度自适应与元素宽度100%是否相等?同时设置margin-left:100px
不同
元素宽度自适应宽度=100px+auto=浏览器窗口宽
元素宽度100%=100px+100%>浏览器窗口宽
高度自适应:不给元素设置高度就是高度自适应
元素默认高度:height:auto
元素内部内容过少会导致容器高度太小,影响页面布局,不美观,需要给容器设置最小高度
min-height--------最小高度(常用)
max-height--------最大高度
max-width--------最大宽度
min-width--------最小宽度(常用)
窗口自适应:元素随着窗口的变化而变化,只需要一行代码实现
html,body{
height:100%;
}
两栏三栏布局:
一侧宽度固定。另一侧宽度占剩余宽度所有
方法一:宽度自适应
方法二:calc()函数
calc函数支持加减乘除,注意运算符前后需要加空格
两栏布局:
<!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>
*{
margin:0;
padding:0;
}
/* 窗口自适应 */
html,body{
height:100%;
}
.lef{
width:300px;
height:100%;
background-color: red;
float: left;
}
/* .rig{
height:100%;
background-color: green;
margin-left:300px;
} */
.rig{
width:calc(100% - 300px);
height:100%;
background-color: green;
float: left;
}
</style>
</head>
<body>
<div class="lef"></div>
<div class="rig"></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>
*{
margin:0;
padding:0;
}
html,body{
height:100%;
}
.lef{
width:200px;
height:100%;
background-color: pink;
float: left;
}
.rig{
width:300px;
height:100%;
background-color: blueviolet;
float: left;
}
.cen{
width:calc(100% - 500px);
height:100%;
background-color: yellowgreen;
float: left;
}
</style>
</head>
<body>
<div class="lef"></div>
<div class="cen"></div>
<div class="rig"></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>
*{
margin:0;
padding: 0;
}
html,body{
height:100%;
}
.top{
height:100px;
background-color: red;
}
.bot{
height:calc(100% - 100px);
background-color: aqua;
}
.bot .lef{
width:300px;
height:100%;
background-color: orange;
float: left;
}
.bot .rig{
width:calc(100% - 300px);
height:100%;
background-color: plum;
float: left;
}
</style>
</head>
<body>
<div class="top"></div>
<div class="bot">
<div class="lef"></div>
<div class="rig"></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>
*{
margin:0;
padding: 0;
}
html,body{
height:100%;
}
.top{
height:90px;
background-color: pink;
}
.bot{
height:100px;
background-color: red;
}
.cen{
height:calc(100% - 190px);
background-color: orange;
}
.lef{
width:200px;
height:100%;
background-color: yellow;
float: left;
}
.rig{
width:300px;
height:100%;
background-color: greenyellow;
float: left;
}
.centerBox{
width:calc(100% - 500px);
height:100%;
background-color: plum;
float: left;
}
</style>
</head>
<body>
<div class="top"></div>
<div class="cen">
<div class="lef"></div>
<div class="centerBox"></div>
<div class="rig"></div>
</div>
<div class="bot"></div>
</body>
</html>
伪元素:
:first-line-----------匹配多行文本中的第一行
:first-letter---------匹配多行文本中的第一个字符
:before---------------向标签前面插入内容
:after----------------向标签后面插入内容
需要配合content一起使用
p::before{
content: '123';
}
p::after{
content: '000';
}
万能清除法:
.clearFix:after{
content: '000';
display: block;
clear: both;
/* 隐藏元素 */
height:0;
visibility: hidden;
opacity: 0;
transform: scale(0);
font-size: 0;
}
浮动框架集:iframe,向页面中插入页面
<iframe src="head.html" frameborder="0" scrolling="no"></iframe>
src-------引入页面路径
frameborder-------框架的边框
取值:
0-----没有边框
1-----有边框
scrolling-------是否有滚动条
取值:
yes/no
默认iframe下面会产生留白,display:block取消下面留白
BFC:会计格式化上下文,独立的区域,与外部互不影响
触发条件:
1、html就是一个BFC
2、元素浮动,float取值不为none,就触发BFC
3、overflow取值不为visible触发BFC
4、display:inline-block/flex/inline-flex
5、position:absolute/fixed
应用场景:
1、兄弟关系中上下margin重叠问题
2、解决父元素高度塌陷
2、两栏宽度自适应布局
-->
</body>