浮动定义及其练习

一、浮动的定义:
元素脱离文档流,按照指定的方向移动,遇到父级边界换行

二、浮动的作用:
解决水平布局

三、浮动的取值
1.left:左浮动
2.right:右浮动
3.none:不浮动
4.inherit:继承父级

四、语法:float:none/left/right/inherit

五、浮动的特点
1.元素脱离文档流
2.默认内容撑开宽高
3.行标签支持所有css样式
4.所有标签同排显示

六、样例代码

<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>浮动练习</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        .news_list {
            list-style: none;
            height: 230px;
            width: 260px;
            background-color: #eef0f5;
        }
        
        .news_list .news {
            width: 260px;
            height: 36px;
        }
        
        .news_list .news .news1 {
            width: 180px;
            overflow: hidden;
        }
        
        .news_list .news p {
            float: left;
            height: 36px;
            line-height: 36px;
            font-size: 13px;
        }
        
        .news_list .news .hot {
            background-color: #ff5d00;
            width: 16px;
            height: 16px;
            margin-top: 10px;
            color: white;
            line-height: 16px;
            text-align: center;
            border-radius: 3px;
            /* margin-left: 5px; */
            font-size: 12px;
        }
    </style>
</head>
 
<body>
    <ul class="news_list">
        <li class="news">
            <p style="color: #ff001a; width: 30px; text-align: center;">1</p>
            <p class="news1" style="color: #5d595a;">那就让我们祝星有野生日快乐</p>
            <p class="hot">沸</p>
        </li>
        <li class="news">
            <p style="color: #ff001a; width: 30px; text-align: center;">2</p>
            <p class="news1" style="color: #5d595a;">我总不能耗尽一生,只用来</p>
 
        </li>
        <li class="news">
            <p style="color: #fba100; width: 30px; text-align: center;">3</p>
            <p class="news1" style="color: #5d595a;">重铸四月番荣光!吾辈义不容辞</p>
        </li>
        <li class="news">
            <p style="color: #878c9c; width: 30px; text-align: center;">4</p>
            <p class="news1" style="color: #5d595a;">今天你学习打代码了吗,</p>
        </li>
        <li class="news">
            <p style="color: #878c9c; width: 30px; text-align: center;">5</p>
            <p class="news1" style="color: #5d595a;">每天都有人摆烂,为什么不是我</p>
        </li>
        <li class="news">
            <p style="color: #878c9c; width: 30px; text-align: center;">6</p>
            <p class="news1" style="color: #5d595a;">百兽之王最强最后杀招!</p>
        </li>
    </ul>
 
</body>
 
</html>

七、样例展示
在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值