CSSDay01--Notes(Box模型+float属性)

一、Box模型


<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>菜单实现</title>
    <style type="text/css">
        ul {
            list-style-type: none;
            float: left;
            padding: 0px;
            background-color: silver;
        }
        ul li {
            float: left;
        }
        ul a {
            display: block;
            width: 50px;
            height: 30px;
            padding: 5px 10px;
            text-decoration: none;
        }
        li a:hover {
            background-color: pink;
            color: red;
        }
    </style>
</head>

<body>
    <ul>
        <li><a href="#">新闻</a>
        </li>
        <li><a href="#">运动</a>
        </li>
        <li><a href="#">国学</a>
        </li>
        <li><a href="#">娱乐</a>
        </li>
    </ul>
</body>

</html>

运行结果:


二、float属性

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>清除浮动</title>
    <style type="text/css">
        #d1 {
            height: 200px;
            border: 1px solid;
        }
        #d2 {
            height: 100px;
            border: 1px solid;
        }
        #d3 {
            height: 50px;
            border: 1px solid;
        }
        #p1 {
            height: 50px;
            clear: both;
        }
        #p2 {
            height: 50px;
            clear: both;
        }
        #div1 {
            width: 20%;
            height: 50px;
            background-color: #F92672;
            float: left;
        }
        #div2 {
            width: 30%;
            height: 50px;
            background-color: #E6DB74;
            float: right;
            clear: left;
        }
        #div3 {
            width: 40%;
            height: 50px;
            background-color: #A6E22E;
            float: left;
            clear: right;
        }
        #div4 {
            width: 50%;
            height: 50px;
            background-color: #66D9EF;
            float: right;
            clear: left;
        }
        #div5 {
            width: 20%;
            height: 50px;
            background-color: #FF8C00;
            float: left;
            clear: right;
        }
        #div6 {
            width: 20%;
            height: 50px;
            background-color: #AE81FF;
            float: right;
        }
        #div7 {
            width: 20%;
            height: 50px;
            background-color: #75715E;
            float: left;
            clear: right;
        }
        #div8 {
            width: 20%;
            height: 50px;
            background-color: #FFC0CB;
            float: right;
        }
        #div9 {
            width: 20%;
            height: 50px;
            background-color: #FF8C00;
            float: left;
            clear: right;
        }
        #div10 {
            width: 20%;
            height: 50px;
            background-color: #AE81FF;
            float: left;
        }
        #div11 {
            width: 20%;
            height: 50px;
            background-color: #75715E;
            float: right;
            clear: right;
        }
        #div12 {
            width: 20%;
            height: 50px;
            background-color: #FFC0CB;
            float: right;
        }
    </style>
</head>

<body>
    <div id="d1">
        <div class="mydiv" id="div1">div1</div>
        <div class="mydiv" id="div2">div2</div>
        <div class="mydiv" id="div3">div3</div>
        <div class="mydiv" id="div4">div4</div>
    </div>
    <div id="p1"></div>
    <div id="d2">
        <div class="mydiv" id="div5">div5</div>
        <div class="mydiv" id="div6">div6</div>
        <div class="mydiv" id="div7">div7</div>
        <div class="mydiv" id="div8">div8</div>
    </div>
    <div id="p2"></div>
    <div id="d3">
        <div class="mydiv" id="div9">div9</div>
        <div class="mydiv" id="div10">div10</div>
        <div class="mydiv" id="div11">div11</div>
        <div class="mydiv" id="div12">div12</div>
    </div>
</body>

</html>

运行结果:

Copyright © 2018 Jin Hanquan. All rights reserved.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值