<!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>
.main {
display: flex;
/* flex-direction: column; 主轴方向改为竖向排列 row为横向 */
/* flex-wrap: nowrap; 不换行 */
/* justify-content: center; 主轴对齐方式 */
/* align-items: center; 交叉轴对齐方式 */
height: 900px;
background-color: #ccc;
}
.f1,
.f2,
.f3,
.f4 {
/* width: 600px; */
width: 200px;
height: 200px;
}
.f1 {
background-color: red;
}
.f2 {
background-color: violet;
}
.f3 {
/* order: -1; 值越小越靠前 */
/* flex-grow: 5; 放大比例 */
/* flex-shrink: 0; 缩小比例,如果超出父元素宽度,设置了该属性为0的元素,宽度不会缩小,其余等比例缩小 */
/* flex-basis: 500px; 当flex-basis和width属性同时存在时,width属性不生效,flex item的宽度为flex-basis设置的宽度 */
/* align-self: flex-end; 单独设置该元素的对齐方式 */
background-color: khaki;
}
.f4 {
background-color: pink;
}
</style>
</head>
<body>
<div class="main">
<div class="f1">1</div>
<div class="f2">2</div>
<div class="f3">3</div>
<div class="f4">4</div>
</div>
</body>
</html>
flex 布局 直接复制粘贴,一项一项测试即可。
最新推荐文章于 2024-10-31 19:42:08 发布