- 主轴: Flex容器的主轴主要是用来配置Flex项目,默认是水平方向。
- 侧轴: 与主轴垂直的轴称作侧轴,默认是垂直方向的。
- 方向: 默认主轴从左往右,侧轴从上到下。 主轴和侧轴并不是固定不变的,通过flex-direction可以互换
对浏览器的支持不一致
属性详解
1.min-width 最小宽度 、max-width 最大宽度 2.flex-direction 调整主轴方向(默认为水平方向) flex-direction:column(垂直排列) flex-direction:row(水平排列)
<!DOCTYPE html>
<html lang="zh">
<head>
<title></title>
</head>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
body {
min-width: 320px;
max-width: 540px;
background-color: white;
margin: 0 auto;
}
header {
height: 108px;
}
header img {
height: 100%;
width: auto;
}
nav {
border: 1px solid #ccc;
padding: 4px;
}
.row {
height: 90px;
display: flex;
border-radius: 5px;
overflow: hidden;
margin-bottom: 5px;
}
.row div {
height: 100%;
flex: 1;
background-color: #ff687a;
border-right: 1px solid white;
}
.row div:nth-child(3) {
border-right: 0;
}
.row div a {
display: block;
}
.row33 {
display: flex;
flex-direction: column;
}
.row33 a {
flex: 1;
text-align: center;
line-height: 45px;
}
.row33 a:first-child {
border-bottom: 1px solid white;
}
nav a {
text-decoration: none;
color: white;
font-size: 14px;
text-shadow: 0 2px 1px rgba(0, 0, 0, .2);
}
.row em {
display: block;
height: 45px;
line-height: 45px;
text-align: center;
font-style: normal;
}
.row i {
display: block;
height: 43px;
width: 43px;
margin: -5px auto;
background: url(images/ctrip.png) no-repeat 0 -127px;
background-size: 104px auto;
/* 浏览器前缀 */
-webkit-background-size: 104px;
-moz-background-size: 104px;
-ms-background-size: 104px;
-o-background-size: 104px;
background-position: 0 -288px;
}
.row .icon-flight {
background-position: 0 -124px;
}
</style>
<body>
<header>
<img src="images/banner.jpg" alt="">
</header>
<nav>
<div class="row">
<div><a href="#">
<em>酒店</em>
<i class="icon-flight"></i>
</a>
</div>
<div class="row33">
<a href="#">海外酒店</a>
<a href="#">特价酒店</a>
</div>
<div class="row33">
<a href="#">团购</a>
<a href="#">民宿客栈</a>
</div>
</div>
<div class="row">
<div><a href="#">
<em>酒店</em>
<i></i>
</a>
</div>
<div class="row33">
<a href="#">海外酒店</a>
<a href="#">特价酒店</a>
</div>
<div class="row33">
<a href="#">团购</a>
<a href="#">民宿客栈</a>
</div>
</div>
<div class="row">
<div><a href="#">
<em>酒店</em>
<i></i>
</a>
</div>
<div class="row33">
<a href="#">海外酒店</a>
<a href="#">特价酒店</a>
</div>
<div class="row33">
<a href="#">团购</a>
<a href="#">民宿客栈</a>
</div>
</div>
<div class="row">
<div class="row33">
<a href="#">海外酒店</a>
<a href="#">特价酒店</a>
</a>
</div>
<div class="row33">
<a href="#">海外酒店</a>
<a href="#">特价酒店</a>
</div>
<div class="row33">
<a href="#">团购</a>
<a href="#">民宿客栈</a>
</div>
</div>
</nav>
</body>
</html>
复制代码
- justify-content 调整主轴对齐(水平对齐) align-items 调整侧轴对齐(垂直对齐)
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title></title>
<style type="text/css">
section {
width: 80%;
height: 150px;
margin: 100px auto;
/* 给父亲添加 伸缩布局 */
display: flex;
/* section 最小的宽度是500 */
min-width: 500px;
/*默认水平分布:row , 垂直分布
reverse翻转
*/
flex-direction: row-reverse;
}
section div {
height: 100%;
}
section div:nth-child(1) {
background-color: pink;
width: 200px;
}
section div:nth-child(2) {
background-color: purple;
flex: 2;
}
section div:nth-child(3) {
background-color: red;
flex: 1;
}
</style>
</head>
<body>
<section>
<div>1</div>
<div>2</div>
<div>3</div>
</section>
</body>
</html>
复制代码