浮动#CSS

Hellow大家好!我们今天来学习浮动啦,这是一个非常简单且经常使用的样式哦,还是那句话勤加练习哈!

来看代码!

div{

width: 100px;

height: 100px;

border: 1px solid red;

}

<div></div>

<div></div>

<div></div>

<div></div>

因为他是快元素嘛所以独占一行,排成了四个竖着的方块

我给他添加浮动元素来看一下

tyle>

    div{

        width: 100px;

        height: 100px;

        border: 1px solid red;

        float: left;

    }

 <div></div>

    <div></div>

    <div></div>

    <div></div>

这个float啊能控制元素像指定位置排列,这个属性值为left,如果是right那就是向右排列啦

我们换成四个大小不一的方块再试一下

.one{

    width: 100px;

    height: 100px;

    border: 1px solid red;

}

.two{

    width: 120px;

    height: 120px;

    border: 1px solid blue;

}

.three{

    width: 80px;

    height: 80px;

    border: 1px solid green;

}

.four{

    width: 120px;

    height: 80px;

    border: 1px solid pink;

}

 <div class="one"></div>

    <div class="two"></div>

    <div class="three"></div>

    <div class="four"></div>

我们接着来看四个大小不一颜色不一的方块能不能完成浮动呢!

.one{

    width: 100px;

    height: 100px;

    border: 1px solid red;

}

.two{

    width: 120px;

    height: 120px;

    border: 1px solid blue;

}

.three{

    width: 80px;

    height: 80px;

    border: 1px solid green;

}

.four{

    width: 120px;

    height: 80px;

    border: 1px solid pink;

}

    div{

        float: left;

    }

  <div class="one"></div>

    <div class="two"></div>

    <div class="three"></div>

    <div class="four"></div>

答案当然也是可以的啦!浮动在用于排列整行元素的时候用的比较多一点

本次的更新就到这里啦,点个关注再走哦! 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值