div布局中对浮动的理解

首先,我们要知道:在标准流的情况下,div块的排列顺序为按照html代码从上自下依次排列。但是在我们设置了浮动(flaot)属性后,div块的排列顺序有所改变。

实验代码:

<!DOCTYPE html>
<html lang="en" style="height: 100%">
<head>
    <meta charset="UTF-8">
    <title>div布局</title>
    <style type="text/css">
    body{
        height: 100%;
        margin: 0;
    }
        #container{
            width: 100%;
            height: 100%;
            background-color: aqua;
        }
        #heading{
            width: 10%;
            height:10%;
            background-color:darkcyan;


        }
        #content_menu{
            width: 30%;
            height: 20%;
            background-color: blue;
        }
        #content_body{
            width:  30%;
            height: 20%;
            background-color: blueviolet;
        }
        #footing{
            width: 10%;
            height: 10%;
            background-color: brown;
        }
    </style>
</head>
<body>
    <div ID="container">
        <div ID="heading">头部</div>
        <div id="content_menu">内容菜单</div>
        <div id="content_body">内容主体</div>
        <div id="footing">底部</div>
    </div>
</body>

</html>

这是标准流中的div块的排列情况:


然后我们对heading部分设置为向左浮动:

#heading{
            width: 10%;
            height:10%;

            background-color:darkcyan;

            float:left;

            

此时的排列情况为:


继续对content_menu部分设置为向左浮动:

#content_menu{
            width: 30%;
            height: 20%;

            background-color: blue;

            float:left;

        }

可见结果为:


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值