flex布局有一个默认的规则就是当父元素宽度不够用时,自己调整自己所占的宽度比,这个flex-shrink设置为1时,表示所有子元素大家同时缩小来适应总宽度。当flex-shrink设置为0时,表示大家都不缩小适应。
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>test</title>
<style type="text/css">
.div1{
width: 300px;
height: 200px;
background-color: red;
overflow-x: scroll;
display: flex;
}
.div1 span{
flex-shrink:0;
width: 100px;
background-color: gray;
margin-left: 20px;
}
</style>
</head>
<body>
<div class="div1">
<span>1</span>
<span>1</span>
<span>1</span>
<span>1</span>
<span>1</span>
<span>1</span>
<span>1</span>
<span>1</span>
<span>1</span>
<span>1</span>
</div>
</body>
</html>