1.css实现瀑布流
2.盒模型
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.one{
width: 200px;
height: 200px;
padding: 5px;
margin: 5px;
border: 5px solid black;
background-color: red;
}
.two{
box-sizing: border-box;
width: 200px;
height: 200px;
padding: 5px;
margin: 5px;
border: 5px solid black;
background-color: yellow;
}
</style>
</head>
<body>
<div class="one"></div>
<div class="two"></div>
</body>
</html>
3.BFC
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box1 {
display: flex;
margin-bottom: 50px;
border: 1px solid black;
}
.box1 .one {
width: 100px;
height: 100px;
margin: 10px;
background-color: red;
float: left;
}
.box2 {
margin-bottom: 50px;
border: 1px solid black;
}
.box2 .one {
width: 100px;
height: 100px;
margin: 10px;
background-color: red;
}
.box2 .parent{
overflow: hidden;
}
.box2 .parent .two {
width: 100px;
height: 100px;
margin: 10px;
background-color:yellow;
}
.box3 {
margin-bottom: 50px;
border: 1px solid black;
}
.box3 .one {
width: 100px;
height: 100px;
margin: 10px;
background-color: red;
float: left;
}
.box3 .two {
width: 100px;
height: 100px;
margin: 10px;
background-color:yellow;
overflow: hidden;
}
</style>
</head>
<body>
<div class="box1">
<div class="one"></div>
</div>
<div class="box2">
<div class="one"></div>
<div class="parent">
<div class="two"></div>
</div>
</div>
<div class="box3">
<div class="one"></div>
<div class="two"></div>
</div>
</body>
</html>
4.IFC
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box1{
border: 1px solid black;
text-align: center;
}
.box1 .one{
display: inline-block;
width: 100px;
height: 100px;
background-color: red;
vertical-align: bottom;
}
.box2{
height: 100px;
border: 1px solid black;
}
.box2 .one{
line-height: 100px;
vertical-align: middle;
}
.box2 .two{
display: inline-block;
width: 25px;
height: 25px;
background-color: red;
}
</style>
</head>
<body>
<div class="box1">
<span class="one"></span>
</div>
<div class="box2">
<i class="one"></i>
<span class="two"></span>
</div>
</body>
</html>
5.选择器及其优先级
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
基本选择器
1.ID选择器
2.class选择器
3.标签选择器
4.*通配符选择器
其他选择器
1.并集选择器
2.交集选择器
3.后代选择器
4.子代选择器
5.属性选择器
6.兄弟选择器
伪类选择器
1.:hover
2.:active
3.:focus
4.:blur
5.:checked
6.:target
7.:first-child
8.:last-child
9.:nth-child
10.:not
伪元素选择器
1.before
2.after
3.first-letter
4.first-line
优先级
1.!important 1000
2.ID选择器 100
3.class选择器 10
4.元素选择器 1
5.*通配符选择器 0-1
</body>
</html>
6.flex弹性布局
7.Grid网格布局
8.元素居中问题
<!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>
.case1{
width: 300px;
height: 300px;
background-color: red;
margin: 0 auto;
}
.case2{
width: 300px;
height: 300px;
background-color: red;
text-align: center;
}
.case2 div{
display: inline-block;
width: 100px;
height: 100px;
background-color: blue;
}
.case3{
width: 300px;
height: 300px;
background-color: red;
display: flex;
justify-content: center;
}
.case3 div{
width: 100px;
height: 100px;
background-color: blue;
}
</style>
</head>
<body>
<div class="case1"></div>
<br>
<div class="case2">
<div></div>
</div>
<br>
<div class="case3">
<div></div>
</div>
<br>
</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>
.case1{
width: 300px;
height: 300px;
line-height: 300px;
background-color: red;
margin: 0 auto;
}
.case2{
width: 300px;
height: 300px;
background-color: red;
margin: 0 auto;
display: flex;
align-items: center;
}
.case2 div{
width: 100px;
height: 100px;
background-color: blue;
}
</style>
</head>
<body>
<div class="case1">
<span>123</span>
</div>
<br>
<div class="case2">
<div>123</div>
</div>
</body>
</html>
10.三列布局
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.container1{
border: 1px solid black;
overflow: hidden;
}
.container1 .left{
width: 200px;
height: 200px;
background-color: red;
float: left;
}
.container1 .center{
width: 200px;
height: 200px;
background-color: pink;
float: left;
}
.container1 .right{
width: 200px;
height: 200px;
background-color: yellow;
float: left;
}
.container2{
border: 1px solid black;
display: flex;
justify-content:center;
}
.container2 .left{
width: 200px;
height: 200px;
background-color: red;
}
.container2 .center{
width: 200px;
height: 200px;
background-color: pink;
}
.container2 .right{
width: 200px;
height: 200px;
background-color: yellow;
}
</style>
</head>
<body>
<div class="container1">
<div class="left"></div>
<div class="center"></div>
<div class="right"></div>
</div>
<div class="container2">
<div class="left"></div>
<div class="center"></div>
<div class="right"></div>
</div>
</body>
</html>
11.如何使一个元素消失
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.one{
display: none;
}
.two{
visibility: hidden;
}
.tree{
opacity: 0;
}
</style>
</head>
<body>
<div class="one">123</div>
<div class="two">456</div>
<div class="tree">789</div>
<script>
const two = document.querySelector(".two");
const tree = document.querySelector(".tree");
two.addEventListener("click",function(){
console.log("two");
},false)
tree.addEventListener("click",function(){
console.log("tree");
},false)
</script>
</body>
</html>
12.nth-of-type与nth-child的区别
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
span:nth-of-type(2){
background-color: red;
}
p:nth-child(2){
background-color: yellow;
}
</style>
</head>
<body>
<div>
<span>1</span>
<p>2</p>
<span>3</span>
<p>4</p>
<span>5</span>
<p>6</p>
</div>
</body>
</html>
13.px、rem、em、vw、vh、%
px像素
rem根元素font-size
em父元素font-size
vw视口宽度
vh视口高度
14.Meta 标签中的 viewport 属性及含义
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta
name="viewport"
content="width=device-width,
user-scalable=no,
initial-scale=1.0,
maximum-scale=1.0,
minimum-scale=1.0"
/>
<title>Document</title>
</head>
<body>
</body>
</html>
15.移动端适配方案
1.百分比布局
2.rem
3.flex
4.grid
5.媒体查询
16.如何实现字体小于12px?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.content{
font-size: 12px;
transform: scale(0.5);
}
svg text{
font-size: 6px;
}
</style>
</head>
<body>
<div class="content">123</div>
<svg width="100" height="30">
<text>
<tspan x="0" dy="6">456</tspan>
</text>
</svg>
</body>
</html>
17.background
background-color
background-image
background-repeat
background-position:
背景图片放置的起始点
background-origin:
规定background-position相对于什么位置来定位
background-attachment:
背景图片是固定还是随着页面的其余部分滚动
background-size:
cover 图片同比缩放至完全覆盖元素,图片可能被截取
contain 图片同比缩放至宽高有一条填充满元素,图片不会存在截取
background-clip:
背景图片裁剪保留区域
18.float
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.container1{
overflow: hidden;
border: 1px solid black;
}
.container1 .one{
width: 100px;
height: 100px;
background-color: red;
float: left;
}
.container2{
border: 1px solid black;
}
.container2 .one{
width: 100px;
height: 100px;
background-color: red;
float: left;
}
.container2 .two{
clear: both;
}
.container3{
border: 1px solid black;
}
.container3 .one{
width: 100px;
height: 100px;
background-color: red;
float: left;
}
.container3::after{
display: block;
content: '';
clear: both;
}
</style>
</head>
<body>
<div class="container1">
<div class="one"></div>
</div>
<div class="container2">
<div class="one"></div>
<div class="two"></div>
</div>
<div class="container3">
<div class="one"></div>
</div>
</body>
</html>
19.position
1.position:relative 相对定位
2.position:absolute 绝对定位
3.position:fixed 固定定位
4.position:sticky 粘性定位
vertical-align
<!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>
.case1{
border: 1px solid black;
}
.case1 img{
vertical-align: bottom;
}
.case2{
border: 1px solid black;
}
.case2 img{
vertical-align: bottom;
}
.case3{
border: 1px solid black;
}
.case3 img{
vertical-align: bottom;
}
.case4{
border: 1px solid black;
}
.case4 img{
vertical-align: bottom;
}
.case4 span{
vertical-align: baseline;
}
.case4 input{
vertical-align: middle;
}
</style>
</head>
<body>
<div class="case1">
<img height="200" src="./bindundun.jpeg" alt="kobe">
<span>123</span>
</div>
<br>
<div class="case2">
<img height="200" src="./bindundun.jpeg" alt="kobe">
<img height="200" src="./bindundun.jpeg" alt="kobe">
</div>
<br>
<div class="case3">
<img height="200" src="./bindundun.jpeg" alt="kobe">
</div>
<br>
<div class="case4">
<img height="200" src="./bindundun.jpeg" alt="kobe">
<span>123</span>
<input type="button" value="按钮"/>
</div>
</body>
</html>