CSS布局——三个DIV横向竖向平均布局

编程入门 行业动态 更新时间:2024-10-20 20:36:46

CSS<a href=https://www.elefans.com/category/jswz/34/1770549.html style=布局——三个DIV横向竖向平均布局"/>

CSS布局——三个DIV横向竖向平均布局

一、正常默认布局

html代码

    <div class="div-big"><div class="div-small" style="background-color: lightcoral;"></div><div class="div-small" style="background-color: lightgoldenrodyellow;"></div><div class="div-small" style="background-color: lightskyblue;"></div></div>

css代码

.div-big{width: 600px;height: 400px;background-color: lightseagreen;/*绿背景色*/
}
.div-big .div-small{width: 100px;height: 100px;
}

图片演示:

二、横向平均排列

html代码

    <div class="div-big"><div class="div-small" style="background-color: lightcoral;"></div><div class="div-small" style="background-color: lightgoldenrodyellow;"></div><div class="div-small" style="background-color: lightskyblue;"></div></div>

css代码

.div-big{width: 600px;height: 400px;background-color: lightseagreen;/*绿背景色*/display: flex;/*重要*/justify-content: space-between;/*重要*/
}
.div-big .div-small{width: 100px;height: 100px;
}

图片演示

提示:

1.justify-content属性值有space-between(常用),space-around(常用),start,end,center.

三、竖向平均排列

html代码

    <div class="div-big"><div class="div-small" style="background-color: lightcoral;">1</div><div class="div-small" style="background-color: lightgoldenrodyellow;">2</div><div class="div-small" style="background-color: lightskyblue;">3</div></div>

css代码

.div-big{width: 600px;height: 400px;background-color: lightseagreen;/*绿背景色*/display: flex;/*重要*/flex-wrap: wrap;/*重要*/    /*--让弹性盒元素在必要的时候拆行:*/align-content: space-between;/*重要*/
}
.div-big .div-small{width: 600px;/*重要*/   /*宽度一定要超过父类横向50%大小*/height: 100px;
}

图片演示

提示:

1.竖向平均排列是加了一行拆分属性flex-wrap: wrap;

2.子类宽度一定要注意超过父类50%的宽度,否则就会横向不拆分成竖向的。

3.justify-content属性值有space-between(常用),space-around(常用),start,end,center.

更多推荐

CSS布局——三个DIV横向竖向平均布局

本文发布于:2024-02-10 21:54:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1677501.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:布局   横向   平均   CSS   DIV

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!