1、字体引入
效果:(有个疑惑,不知为啥,字体对于中文字体为效果,英文字体就可以)
代码:
<!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>
@font-face{
font-family: lbb;
src: url(font/KUNSTLER.TTF);
}
div{
font-family: lbb;
font-size: 100px;
color: red;
text-shadow: 5px 0px 0px violet;
}
</style>
</head>
<body>
<div>Jack</div>
</body>
</html>
2、怪异盒模型
(1)例子1
效果:
代码:
<!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>
.box1{
width: 200px;
height: 200px;
background: green;
padding: 30px;
border: 10px solid black;
/* 标准盒模型 */
box-sizing: content-box;
}
.box2{
width: 200px;
height: 200px;
background: rebeccapurple;
margin-top: 100px;
padding: 30px;
border: 10px solid black;
/* 怪异盒模型 */
box-sizing: border-box;
}
</style>
</head>
<body>
<div class="box1"></div>
<div class="box2"></div>
</body>
</html>
(2)例子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>
.box{
width: 900px;
height: 300px;
background: yellow;
}
.box div{
width: 300px;
height: 300px;
float: left;
text-align: center;
padding: 10px;
border: 2px solid rebeccapurple;
box-sizing: border-box;
}
</style>
</head>
<body>
<div class="box">
<div>Lorem ipsum dolor sit amet consectetur adipisicing elit. Corrupti esse voluptatum quis cum, accusamus asperiores. Voluptatum debitis blanditiis dignissimos odio aliquid sed minima! Tempora explicabo quos tempore incidunt beatae neque!</div>
<div>Lorem ipsum dolor sit amet consectetur adipisicing elit. Corrupti esse voluptatum quis cum, accusamus asperiores. Voluptatum debitis blanditiis dignissimos odio aliquid sed minima! Tempora explicabo quos tempore incidunt beatae neque!</div>
<div>Lorem ipsum dolor sit amet consectetur adipisicing elit. Corrupti esse voluptatum quis cum, accusamus asperiores. Voluptatum debitis blanditiis dignissimos odio aliquid sed minima! Tempora explicabo quos tempore incidunt beatae neque!</div>
</div>
</body>
</html>
3、弹性盒display: flex
弹性盒是一种新的布局方式,特别适合移动端布局
影响:1、子元素默认横向排列
2、行内元素,变成块级元素
3、只有一个元素的时候,margin:auto 自动居中
效果:
代码:
<!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: 500px;
height: 500px;
border: 1px solid black;
margin: 100px auto;
/* 弹性盒 */
display: flex;
}
.box div{
width: 100px;
height: 100px;
border: 1px dashed rebeccapurple;
}
</style>
</head>
<body>
<div class="box">
<div>111</div>
<div>222</div>
<div>333</div>
<div>444</div>
</div>
</body>
</html>
4、弹性盒-修改主轴方向flex-direction
默认情况
可以这样修改
效果:
代码:
<!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: 500px;
height: 500px;
border: 1px solid black;
margin: 100px auto;
/* 弹性盒 */
display: flex;
/* 改变主轴 */
/* 值:row 行
column 列
row-reverse 行反向
column-reverse 列反向
*/
flex-direction: column;
}
.box div{
width: 100px;
height: 100px;
border: 1px dashed rebeccapurple;
}
</style>
</head>
<body>
<div class="box">
<div>111</div>
<div>222</div>
<div>333</div>
<div>444</div>
</div>
</body>
</html>
5、主轴侧轴对齐方式justify-content
效果:
代码:
<!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: 500px;
height: 500px;
border: 1px solid black;
margin: 100px auto;
/* 弹性盒 */
display: flex;
/* 调整主轴对齐方向 */
/* 值:flex-start(默认值) 左边显示
flex-end 右边显示
center 中间显示
space-between 两端对齐
space-around 距离环绕
*/
justify-content: center;
/* 调整侧轴对齐方式 */
/* 值:flex-start(默认值)
flex-end
center
*/
align-items: center;
}
.box div{
width: 100px;
height: 100px;
border: 1px dashed rebeccapurple;
}
</style>
</head>
<body>
<div class="box">
<div>111</div>
<div>222</div>
<div>333</div>
<div>444</div>
</div>
</body>
</html>
6、折行 flex-wrap与行间距 align-content
(1)案例一
效果:
代码:
<!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: 500px;
height: 500px;
border: 1px solid black;
margin: 100px auto;
/* 弹性盒 */
display: flex;
/* 折行 */
flex-wrap: wrap;
/*
控制折行后的行间距
值:flex-start
flex-end
center
space-around
space-between
*/
align-content: flex-start;
}
.box div{
width: 100px;
height: 100px;
border: 1px dashed rebeccapurple;
}
</style>
</head>
<body>
<div class="box">
<div>111</div>
<div>222</div>
<div>333</div>
<div>444</div>
<div>555</div>
<div>666</div>
<div>666</div>
<div>666</div>
<div>666</div>
<div>666</div>
<div>666</div>
<div>666</div>
<div>666</div>
</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>
.box{
width: 300px;
height: 120px;
border: 1px solid black;
margin: 10px auto;
display: flex;
flex-wrap: wrap;
}
.box div{
width: 60px;
height: 60px;
border: 1px dashed red;
box-sizing: border-box;
display: flex;
}
.box div img{
width: 40px;
height: 40px;
margin: auto;
}
</style>
</head>
<body>
<div class="box">
<div><img src="ec560dbf9b82b90b.png" ></div>
<div><img src="ec560dbf9b82b90b.png" ></div>
<div><img src="ec560dbf9b82b90b.png" ></div>
<div><img src="ec560dbf9b82b90b.png" ></div>
<div><img src="ec560dbf9b82b90b.png" ></div>
<div><img src="ec560dbf9b82b90b.png" ></div>
<div><img src="ec560dbf9b82b90b.png" ></div>
<div><img src="ec560dbf9b82b90b.png" ></div>
<div><img src="ec560dbf9b82b90b.png" ></div>
<div><img src="ec560dbf9b82b90b.png" ></div>
</div>
</body>
</html>