flex-direction弹性盒子
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
.box{
width: 100%;
height: 200px;
background-color: aqua;
display: flex;
flex-direction: row;
}
.b_left{
flex: 1;
background-color: blue;
}
.b_right{
flex: 2;
background-color: pink;
}
</style>
</head>
<body>
<!-- 移动端布局,任何容器(包括行内)都可以用flex进行布局 -->
<!-- 使用flex后,子元素的float clear verticle-align失效 -->
<div class="box">
<div class="b_left">1</div>
<div class="b_right">2</div>
</div>
</body>
</html>
弹性布局换行
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
.box{
width:600px;
display: flex;
background-color: #FFC0CB;
flex-wrap: wrap-reverse;
flex-direction: row-reverse;
}
.box div{
width: 100px;
height: 100px;
font-size: 30px;
color: white;
background-color: #00FFFF;
}
</style>
</head>
<body>
<div class="box">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
</div>
</body>
</html>
主轴和副轴的对齐方式
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
.box{
width: 800px;
height: 600px;
background-color: aqua;
display: flex;
align-items: stretch;
}
.son1{
width: 100px;
background-color: #FFC0CB;
}
.son2{
width: 200px;
background-color: #0000FF;
font-size: 50px;
}
.son3{
width: 300px;
background-color: blueviolet;
font-size: 40px;
}
</style>
</head>
<body>
<div class="box">
<div class="son1">1</div>
<div class="son2">2</div>
<div class="son3">3</div>
</div>
</body>
</html>
多根轴线对齐方式
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
.box{
width:1000px;
height: 800px;
border: solid 1px orange;
display: flex;
flex-wrap: wrap;
align-content:stretch;
}
.box div{
width: 200px;
height: 200px;
font-size: 30px;
color: white;
background-color: #00FFFF;
}
</style>
</head>
<body>
<div class="box">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
</div>
</body>
</html>
弹性子元素属性
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
.box{
width:1000px;
height: 800px;
border: solid 1px orange;
display: flex;
flex-wrap: wrap;
}
.box div{
width: 200px;
height: 200px;
font-size: 30px;
color: white;
background-color: #00FFFF;
}
.box1{
order: 5;
}
.box5{
order: 1;
}
</style>
</head>
<body>
<div class="box">
<div class="box1">1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div class="box5">5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
</div>
</body>
</html>
放大和缩小比例
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
.box{
width:1000px;
border: solid 1px orange;
display: flex;
}
.box div{
width: 600px;
height: 200px;
font-size: 30px;
color: white;
background-color: #00FFFF;
}
.box1{
flex-shrink: 2;
}
.box5{
flex-shrink:4;
}
</style>
</head>
<body>
<div class="box">
<div class="box1">1</div>
<div>2</div>
<!-- <div>3</div>
<div>4</div> -->
<div class="box5">5</div>
<!-- <div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div> -->
</div>
</body>
</html>
项目占据的主轴空间
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
.box{
width:1000px;
border: solid 1px orange;
display: flex;
}
.box div{
width: 600px;
height: 200px;
font-size: 30px;
color: white;
border: solid 1px #FFA500;
}
.box1{
flex-basis:800px;
}
</style>
</head>
<body>
<!--
flex-basis:数值;
项目占据主轴的空间,等同于width ,数值方向等同于高度。
简写:
flex:grow shrink basis;
auto
none
1 (即 (1,1,0%))
initial (默认 即:(0,1,auto))
-->
<div class="box">
<div class="box1">1</div>
<div>2</div>
<!-- <div>3</div>
<div>4</div> -->
<div class="box5">5</div>
<!-- <div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div> -->
</div>
</body>
</html>
不一样的对齐方式
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
.box{
width:1000px;
height: 800px;
border: solid 1px orange;
display: flex;
}
.box div{
width: 600px;
height: 200px;
font-size: 30px;
color: white;
background-color: #00FFFF;
border: solid 1px orange;
}
.box1{
align-self: stretch;
font-size: 30px !important;
}
</style>
</head>
<body>
<!--
align-self: auto;
flex-start
flex-end
center
baseline
stretch
align-self属性允许单个项目有与其他项目不一样的对齐方式,
可覆盖align-items属性。默认值为auto,表示继承父元素的align-items属性,
如果没有父元素,则等同于stretch。
该属性可能取6个值,除了auto,其他都与align-items属性完全一致。
-->
<div class="box">
<div class="box1">1</div>
<div>2</div>
<!-- <div>3</div>
<div>4</div> -->
<div class="box5">5</div>
<!-- <div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div> -->
</div>
</body>
</html>
媒体查询
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="./CSS/one.css" media="(max-width:768px)">
</head>
<body>
<!-- 格式:
@media 设备 and (设备特性){
}
在外部写完CSS用<link>引入对应的CSS
<link href='css文件' media='(max-width:768px)'>
- 超小屏幕(手机,小于 768px):设置宽度为 100%
- 小屏幕(平板,大于等于 768px):设置宽度为 750px
- 中等屏幕(桌面显示器,大于等于 992px):宽度设置为 970px
- 大屏幕(大桌面显示器,大于等于 1200px):宽度设置为 1170px
-->
<div class="box">
我是768px下的box
</div>
</body>
</html>
媒体查询CSS
.box{
width: 500px;
height: 500px;
background-color: #8A2BE2;
}