100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > 如何让多个div横向排列(html+css)

如何让多个div横向排列(html+css)

时间:2023-04-25 03:33:03

相关推荐

如何让多个div横向排列(html+css)

div是块级元素,是自上而下、垂直排列会占满一行且具有自动换行功能。

方法一:使用flex自适应

<div class="all"><div class="a"></div><div class="b"></div><div class="c"></div></div>

.all{display: flex; /*给父元素设置flex*/}.a,.b,.c{width: 300px;height: 100px; }.a{background-color: black;}.b{background-color: background-color:pink;}.c{background-color: red;}

方法二:使用float浮动方式

<div class="a"></div><div class="b"></div><div class="c"></div>

.a,.b,.c{width: 300px;height: 100px; float: left;/*使三个div向左浮动*/}.a{background-color: black;}.b{background-color:pink;}.c{background-color: red;}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。