div横向布局

来源:互联网 发布:windows 无法访问指定 编辑:程序博客网 时间:2024/06/08 10:59

div有时候是需要多个放在同一行的,但是如果用了float,会导致不能撑开父div的后果。

如果我们要做到一个父div下有一左一右两个子div,右边的子div下还有上下两个div,一般布局非常难搞。

如果右边的个数不定,则更加混乱。

我们可以把div变成inline-block;

代码如下。

<div class="grandfather"><div class="father1" style="display:inline-block;width:50px;height:80px"></div><div class="father2" style="display:inline-block"><div class="son1" style="width:50px;height:50px"></div><div class="son2" style="width:50px;height:50px"></div></div></div>


原创粉丝点击