day07.06.HTML浮动

23 篇文章 0 订阅
11 篇文章 0 订阅

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .box1 {width: 100px; height: 100px; background: orange; float: left;}
        .box2 {width: 100px; height: 100px; background: red; float: left;}
        .box3 {width: 100px; height: 100px; background: blue; float: left;}
        .box4 {width: 100px; height: 100px; background: green; float: left;}
    </style>

<!--
        浮动 float
          作用是水平布局
            float: left ;向左浮动
            float: right ;向右浮动
        如果有一个设置浮动  四个都需要设置浮动 要么全向左要么全向右
                全向右的时候 box1会变成最右边的  比较特殊 ,一般不会设置全部向右

        清浮动: clear:both
            clear:left/right/both
            解决浮动带来的div重叠的影响
    -->


</head>
<body>
    <div class = "box1">box1</div>
    <div class = "box2">box2</div>
    <div class = "box3">box3</div>
    <div class = "box4">box4</div>

    <div style = "clear: both; width: 600px; height: 300px; background: pink;">hello</div>
</body>
</html>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .box1 {width: 100px; height: 100px; background: orange; float: left;}
        .box2 {width: 100px; height: 100px; background: red; float: left;}
        .box3 {width: 100px; height: 100px; background: blue; float: left;}
        .box4 {width: 100px; height: 100px; background: green; float: left;}
    </style>

<!--
        浮动 float
          作用是水平布局
            float: left ;向左浮动
            float: right ;向右浮动
        如果有一个设置浮动  四个都需要设置浮动 要么全向左要么全向右
                全向右的时候 box1会变成最右边的  比较特殊 ,一般不会设置全部向右

        清浮动: clear:both
            clear:left/right/both
            解决浮动带来的div重叠的影响
    -->


</head>
<body>
    <div class = "box1">box1</div>
    <div class = "box2">box2</div>
    <div class = "box3">box3</div>
    <div class = "box4">box4</div>

    <div style = "clear: both; width: 600px; height: 300px; background: pink;">hello</div>
</body>
</html>

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值