先看效果:
代码示例:
问题描述:flex竖向排版,自动换行后,子元素即使有宽度也会平均排列,不能左对齐,这个感觉是很简单,但试了半天没试出来,有没有办法。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#box {
padding: 20px;
margin: 100px auto;
width: 500px;
height: 200px;
line-height: 40px;;
border: 1px solid #000;
display: flex;
flex-flow: column wrap;
align-content: flex-start;
}
#box div {
width: 100px;
border: 1px solid #000;
}
</style>
</head>
<body>
<div id="box">
<div>fire a shot</div>
<div>fire a shot</div>
<div>fire a shot</div>
<div>fire a shot</div>
<div>fire a shot</div>
<div>fire a shot</div>
<div>fire a shot</div>
<div>fire a shot</div>
<div>fire a shot</div>
<div>fire a shot</div>
</div>
</body>
</html>
用align-content,在cross axis分配剩余的空间.
13 回答13k 阅读
8 回答2.9k 阅读
2 回答5.2k 阅读✓ 已解决
5 回答1.4k 阅读
3 回答1.2k 阅读✓ 已解决
3 回答2.3k 阅读✓ 已解决
5 回答1.7k 阅读✓ 已解决
align-content,这么多年没用过这个值,尴尬