父容器设为flex,子项目再设置flex-grow、flex-shrink、flex-basis时,子项目宽度可能无效,这里可能的原因是由于如果flex设置了flex: 0 0 atuo,那么宽度还是有效的,因为auto最终作用在width上,而此时flex-group和flex-shrink也不能伸缩;如果设置成flex: 1 1 0% 就无效了;
- 父容器设置flex,那么子容器的flex-group、flex-shrink、flex-basic优先级比width高!
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.container {
display: flex;
.div1 {
background-color: #ccc;
flex: 1;
width: 300px;
}
.div2 {
background-color: red;
flex: 1;
width: 400px;
}
.div3 {
background-color: green;
width: 100px;
}
}
</style>
</head>
<body>
<div class="container">
<div class="div1">div1111111111111111111111111111111111111111111111123</div>
<div class="div2">div22222222222222222222222222</div>
<div class="div3">div3</div>
</div>
</body>
</html>
1199

被折叠的 条评论
为什么被折叠?



