Thuộc tính flexFlow là shorthand kết hợp flex-direction và flex-wrap. Dùng column nowrap để sắp xếp các item theo cột dọc, không xuống dòng.
Ví dụ minh họa
Container ban đầu flex-flow: row wrap. Nhấn nút để chuyển sang cột không wrap:
<!DOCTYPE html>
<html>
<head>
<style>
#box {
border: 1px solid #000;
width: 100px;
height: 150px;
display: flex;
flex-flow: row wrap;
}
#box div {
height: 40px;
width: 40px;
}
</style>
</head>
<body>
<div id="box">
<div style="background-color:orange;">DIV1</div>
<div style="background-color:blue;">DIV2</div>
<div style="background-color:yellow;" id="myID">DIV3</div>
</div>
<p>Sử dụng thuộc tính flexDirection</p>
<button onclick="display()">Thiết lập</button>
<script>
function display() {
document.getElementById("box").style.flexFlow = "column nowrap";
}
</script>
</body>
</html>
Cú pháp flexFlow
flex-flow: <flex-direction> <flex-wrap>
| Ví dụ | Hành vi |
|---|---|
row nowrap | Hàng ngang, không wrap (mặc định) |
row wrap | Hàng ngang, wrap khi cần |
column nowrap | Cột dọc, không wrap |
column wrap | Cột dọc, wrap khi cần |