微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

几种常见的flex布局

1,水平等距排列、俩端对齐、垂直方向居顶对齐

html:@H_404_3@

<div class="container flex">
    <div class="div1"></div>
    <div class="div2"></div>
    <div class="div3"></div>
</div>

 @H_404_3@

css:@H_404_3@

.container{
    width: 1000px;
    margin: 100px auto;
    border: #333 solid 1px;
    height: 500px;
}
.div1{
    width: 100px;
    height: 120px;
    background-color: yellowgreen;
}
.div2{
    width: 200px;
    height: 150px;
    background-color: salmon;
}
.div3{
    width: 160px;
    height: 200px;
    background-color: bisque;
}
.flex{
    display: flex;
    justify-content: space-between;
}

 @H_404_3@

效果:@H_404_3@

@H_404_3@@H_404_3@

 @H_404_3@

 @H_404_3@

2,水平等距排列、俩端对齐、垂直方向居中对齐

html:@H_404_3@

<div class="container flex">
    <div class="div1"></div>
    <div class="div2"></div>
    <div class="div3"></div>
</div>

 @H_404_3@

css:@H_404_3@

.container{
    width: 1000px;
    margin: 100px auto;
    border: #333 solid 1px;
    height: 500px;
}
.div1{
    width: 100px;
    height: 120px;
    background-color: yellowgreen;
}
.div2{
    width: 200px;
    height: 150px;
    background-color: salmon;
}
.div3{
    width: 160px;
    height: 200px;
    background-color: bisque;
}
.flex{
    display: flex;
    justify-content: space-between;
    align-items: center;
}

 @H_404_3@

效果:@H_404_3@

@H_404_3@@H_404_3@

 @H_404_3@

 @H_404_3@

 @H_404_3@

3,水平等距排列、俩端对齐、垂直方向居底对齐

html:@H_404_3@

<div class="container flex">
    <div class="div1"></div>
    <div class="div2"></div>
    <div class="div3"></div>
</div>

 @H_404_3@

css:@H_404_3@

.container{
    width: 1000px;
    margin: 100px auto;
    border: #333 solid 1px;
    height: 500px;
}
.div1{
    width: 100px;
    height: 120px;
    background-color: yellowgreen;
}
.div2{
    width: 200px;
    height: 150px;
    background-color: salmon;
}
.div3{
    width: 160px;
    height: 200px;
    background-color: bisque;
}
.flex{
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
}

 @H_404_3@

效果:@H_404_3@

@H_404_3@@H_404_3@

 @H_404_3@

4,水平排列、垂直方向居中对齐

html: @H_404_3@

<div class="container flex">
    <div class="div1"></div>
    <div class="div2"></div>
    <div class="div3"></div>
</div>

 @H_404_3@

css:@H_404_3@

.container{
    width: 1000px;
    margin: 100px auto;
    border: #333 solid 1px;
    height: 500px;
}
.div1{
    width: 100px;
    height: 120px;
    background-color: yellowgreen;
}
.div2{
    width: 200px;
    height: 150px;
    background-color: salmon;
}
.div3{
    width: 160px;
    height: 200px;
    background-color: bisque;
}
.flex{
    display: flex;
    align-items: center;
}

 @H_404_3@

效果:@H_404_3@

@H_404_3@@H_404_3@

 @H_404_3@

 @H_404_3@

 @H_404_3@

 @H_404_3@

5,垂直等距排列、俩端对齐、水平方向居中对齐

html:@H_404_3@

<div class="container flex">
    <div class="div1"></div>
    <div class="div2"></div>
    <div class="div3"></div>
</div>

 @H_404_3@

css:@H_404_3@

.container{
    width: 1000px;
    margin: 100px auto;
    border: #333 solid 1px;
    height: 500px;
}
.div1{
    width: 100px;
    height: 120px;
    background-color: yellowgreen;
}
.div2{
    width: 200px;
    height: 150px;
    background-color: salmon;
}
.div3{
    width: 160px;
    height: 200px;
    background-color: bisque;
}
.flex{
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
}

 @H_404_3@

效果:@H_404_3@

@H_404_3@@H_404_3@

 @H_404_3@

6,垂直等距排列、俩端对齐、水平方向居左对齐

html:@H_404_3@

<div class="container flex">
    <div class="div1"></div>
    <div class="div2"></div>
    <div class="div3"></div>
</div>

 @H_404_3@

css:@H_404_3@

.container{
    width: 1000px;
    margin: 100px auto;
    border: #333 solid 1px;
    height: 500px;
}
.div1{
    width: 100px;
    height: 120px;
    background-color: yellowgreen;
}
.div2{
    width: 200px;
    height: 150px;
    background-color: salmon;
}
.div3{
    width: 160px;
    height: 200px;
    background-color: bisque;
}
.flex{
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

 @H_404_3@

效果:@H_404_3@

@H_404_3@@H_404_3@

 @H_404_3@

 @H_404_3@

7,垂直排列、水平方向居中对齐

html:@H_404_3@

<div class="container flex">
    <div class="div1"></div>
    <div class="div2"></div>
    <div class="div3"></div>
</div>

 @H_404_3@

css:@H_404_3@

.container{
    width: 1000px;
    margin: 100px auto;
    border: #333 solid 1px;
    height: 500px;
}
.div1{
    width: 100px;
    height: 120px;
    background-color: yellowgreen;
}
.div2{
    width: 200px;
    height: 150px;
    background-color: salmon;
}
.div3{
    width: 160px;
    height: 200px;
    background-color: bisque;
}
.flex{
    display: flex;
    flex-direction: column;
    align-items: center;
}

 @H_404_3@

效果:@H_404_3@

@H_404_3@@H_404_3@

 @H_404_3@

 @H_404_3@

 @H_404_3@

 @H_404_3@

 @H_404_3@

 @H_404_3@

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐