flex是css专门为布局而诞生的一个属性
用法:
1、首先在外层元素定义一个display:flex
2、在内层元素使用flex: 1
是不是很简单呢?
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
.container {
display: flex;
width: 800px;
height: 300px;
border: 1px dashed red;
background: linear-gradient(0deg, transparent 0, green 30%, red 60%, black 100%)
}
.flex {
flex: 1;
margin: 5px;
background: #adc;
}
.flex2 {
flex: 2;
margin: 5px;
background: #eee;
}
</style>
</head>
<body>
<div class="container">
<div class="flex"></div>
<div class="flex"></div>
<div class="flex2"></div>
</div>
</body>
</html>
效果图:
既然flex这么好用为什么没有大规模的使用呢?
原因是很多浏览器不兼容,并且期间有过几次的语法变动
