会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132358个问题
WEB前端全系列/第一阶段:HTML5+CSS3模块/CSS3新特性 154楼

嗷嗷刚刚代码那个p标签写在div外面了,现在解决了,用两种方式清楚浮动都可以了

    <style>

        *{

            margin: 0;

            padding: 0;

        }

        .nav{

            width: 100%;

            height: 68px;

            background-color: rgba(0,0,0,.85);

        }

        .nav ul {

            list-style: none;

            margin-left: 300px;

            line-height: 68px;

            /* overflow: hidden; */

        }


        .nav ul::after{

            content: "";

            overflow: hidden;

            clear: both;

        }


        .nav ul li{

            float: left;

            padding: 0 20px;

        }


        .nav ul li a{

            text-decoration: none;

            color: white;


        }


        .nav ul li a:hover{

            color: #ff6700;

        }


        p{

            clear: both;

        }


    </style>

</head>

<body>

    <div class="nav">

        <ul>

            <li>

                <a href="#">小米商城</a>

            </li>

            <li>

                <a href="#">小米影像</a>

            </li>

            <li>

                <a href="#">MIUI</a>

            </li>

            <li>

                <a href="#">LOT</a>

            </li>

            <li>

                <a href="#">云服务</a>

            </li>

            <li>

                <a href="#">天星科技</a>

            </li>

            <li>

                <a href="#">有品</a>

            </li>

            <li>

                <a href="#">小爱开放平台</a>

            </li>

            <li>

                <a href="#">企业团购</a>

            </li>

        </ul>

        <p>testtest</p>

    </div>


</body>


WEB前端全系列/第一阶段:HTML5+CSS3模块/浮动与定位 155楼

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <meta name="viewport" content="width=, initial-scale=1.0">

    <title>Document</title>

    <style>

        *{

            margin: 0;

            padding: 0;

        }

        .nav{

            width: 100%;

            height: 68px;

            background-color: rgba(0,0,0,.85);

        }

        .nav ul {

            margin-left: 300px;

        }


        .nav ul li{

            float: left;

            padding: 0 20px;

            display: inline;

        }


        .nav ul li a{

            text-decoration: none;

            color: white;

            line-height: 68px;

        }


        .nav ul li a:hover{

            color: #ff6700;

        }


    </style>

</head>

<body>

    <div class="nav">

        <ul>

            <li>

                <a href="#">小米商城</a>

            </li>

            <li>

                <a href="#">小米影像</a>

            </li>

            <li>

                <a href="#">MIUI</a>

            </li>

            <li>

                <a href="#">LOT</a>

            </li>

            <li>

                <a href="#">云服务</a>

            </li>

            <li>

                <a href="#">天星科技</a>

            </li>

            <li>

                <a href="#">有品</a>

            </li>

            <li>

                <a href="#">小爱开放平台</a>

            </li>

            <li>

                <a href="#">企业团购</a>

            </li>

        </ul>

    </div>

    <p>testtest</p>

</body>

</html>

老师为啥这个结果不用清除浮动,也可以p标签在下面?

image.png

WEB前端全系列/第一阶段:HTML5+CSS3模块/浮动与定位 156楼
WEB前端全系列/第一阶段:HTML5+CSS3模块/浮动与定位 157楼

   <style>
        * {
            margin: 0;
            padding: 0;
        }

        body {
            background-color: aliceblue;
        }

        .container {
            width: 1080px;
            margin: 0 auto;
        }

        .container ul {
            overflow: hidden;
            clear: both;
        }

        .container ul li {
            position: relative;
            float: left;
            list-style: none;
            background-color: #fff;
            margin: 10px 9px 0 0;
            width: 260px;
            height: 375px;
        }

        .container ul li:nth-child(4n) {
            margin-right: 0;
        }

        .container ul li a {
            display: block;
            width: 100%;
            height: 100%;
            text-align: center;
            text-decoration: none;
            padding-top: 20px;
        }

        img {
            width: 250px;
            height: 230px;

        }

        .container ul li a .text {
            width: 100%;
            margin-top: 20px;
        }

        .text .name {
            display: block;
            color: #333;
            font-size: 16px;
            margin-bottom: 3px;
        }

        .text .desc {
            display: block;
            color: #999;
            font-size: 15px;
        }

        .text .price i {
            font-style: normal;
            font-size: 17px;
            color: red;
        }

        .text .price {
            display: inline-block;
            color: red;
            font-size: 22px;
            /* padding-left: 14px; */
        }

        .text .price em {
            font-size: 16px;
            font-style: normal;
        }

        .prodect-sign {
            position: absolute;
            top: 15px;
            left: 20px;
            display: block;
            width: 55px;
            height: 55px;
            background-color: pink;
            border-radius: 60%;
            line-height: 55px;
            color: #fff;
            font-size: 16px;
        }
    </style>
</head>

<body>
    <div class="container">
        <ul>
            <li>
                <a href="#">
                    <img src="./img/1.webp" alt="">
                    <div class="text">
                        <span class="name">小米 11Pro</span>
                        <span class="desc">限时优惠,抢购吧</span>
                        <span class="price"><i>¥</i>1999<em>起</em></span>
                    </div>
                    <span class="prodect-sign">免息</span>
                </a>
            </li>
            <li>
                <a href="#">
                    <img src="./img/2.png" alt="">
                    <div class="text">
                        <span class="name">小米 12Pro</span>
                        <span class="desc">限时优惠,抢购吧</span>
                        <span class="price"><i>¥</i>2999<em>起</em></span>
                    </div>
                    <span class="prodect-sign">免息</span>
                </a>
            </li>
            <li>
                <a href="#">
                    <img src="./img/1.webp" alt="">
                    <div class="text">
                        <span class="name">小米 11U</span>
                        <span class="desc">限时优惠,抢购吧</span>
                        <span class="price"><i>¥</i>2222<em>起</em></span>
                    </div>
                    <span class="prodect-sign">免息</span>
                </a>
            </li>
            <li>
                <a href="#">
                    <img src="./img/2.png" alt="">
                    <div class="text">
                        <span class="name">小米 12U</span>
                        <span class="desc">限时优惠,抢购吧</span>
                        <span class="price"><i>¥</i>3333<em>起</em></span>
                    </div>
                    <span class="prodect-sign">免息</span>
                </a>
            </li>
        </ul>
    </div>
</body>

偷懒用老师写的尺寸,但是看着好大啊,对于类名还是不会起名字,不会管理

image.png

WEB前端全系列/第一阶段:HTML5+CSS3模块/浮动与定位 158楼

    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .nav {
            width: 100%;
            height: 60px;
            position: relative;
            text-align: center;
        }

        .nav ul {
            overflow: hidden;
            clear: both;
        }

        .nav ul li {
            list-style: none;
            float: left;
            padding: 25px 30px;
        }
        .nav ul li a {
            color: #333;
            text-decoration: none;
            font-size: 25px;
        }

        .nav-list {
            width: 100%;
            height: 300px;
            position: absolute;
            left: 0;
            display: none;
        }
        .nav li:hover>.nav-list {
            display: block;
        }
        .nav li:hover>a {
            color: blue;
        }
    </style>
</head>
<body>
    <div class="nav">
        <ul>
            <li>
                <a href="#">首页</a>
                <div class="nav-list" style="background-color:pink";></div>
            </li>
            <li>
                <a href="#">手机</a>
                <div class="nav-list" style="background-color:skyblue";></div>
            </li>
            <li>
                <a href="#">平板</a>
                <div class="nav-list" style="background-color:pink";></div>
            </li>
            <li>
                <a href="#">配件</a>
                <div class="nav-list"  style="background-color:skyblue";></div>
            </li>
            <li>
                <a href="#">服务器</a>
                <div class="nav-list" style="background-color:pink";></div>
            </li>
            <li>
                <a href="#">下载</a>
                <div class="nav-list"  style="background-color:skyblue";></div>
            </li>
        </ul>
    </div>

image.png


WEB前端全系列/第一阶段:HTML5+CSS3模块/浮动与定位 159楼

<style>
        * {
            margin: 0;
            padding: 0;
        }

        .nav {
            width: 100%;
            height: 60px;
            line-height: 60px;
            background-color: #666;
        }

        .nav ul {
            width: 1000px;
            margin: 0 auto;
        }

        .nav ul li {
            list-style: none;
            float: left;
            padding: 0 20px;
        }
       
        .nav ul::after {
            content: "";
            margin: 0 auto;
            display: block;
            clear: both;
        }
        .nav ul li a {
            text-decoration: none;
            font-size: 20px;
            color: #b0b0b0;

        }

        .nav ul li:hover {
            background-color: #222;
        }
    </style>
</head>
<body>
    <div class="nav">
        <ul>
            <li><a href="#">首页</a></li>
            <li><a href="#">电视</a></li>
            <li><a href="#">家电</a></li>
            <li><a href="#">服务</a></li>
            <li><a href="#">平板</a></li>
        </ul>
        <p>hahah</p>
    </div>
</body>

image.png

WEB前端全系列/第一阶段:HTML5+CSS3模块/浮动与定位 160楼
WEB前端全系列/第一阶段:HTML5+CSS3模块/初识CSS 161楼

<!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>Document</title>

    <style>

        body{

            background-color: #f5f5f5;

        }

        .exhibit{

            width: 1226px;

            height: 628px;

            margin: 0 auto;

            /* background-color: aqua; */

        }

        .left{

            float: left;

            width: 234px;

            height: 614px;

            /* background-color: black; */

        }

        .right{

            float: right;

            width: 992px;

            height: 614px;

            /* background-color: #fff; */

        }

        .box{

            float: left;

            width: 234px;

            height: 300px;

            padding: 20 auto;

            margin-bottom: 14px;

            margin-left: 14px;

            background-color: #fff;

            text-align: center;

        }

        .sal{

            height: 160px;

            width:160px;

            margin-top: 20px;

        }

        .ex{

            height: 614px;

            width: 234px;

        }

        .title{

            margin: 0 10px 2px;

            font-size: 14px;

            font-weight: 400;

            color: #333;

            text-align: center;


        }

        .desc{

            margin: 0 10px 10px;

            height: 18px;

            font-size: 12px;

            color: #b0b0b0;

            text-overflow: ellipsis;

            white-space: nowrap;

            text-align: center;

            overflow: hidden;

        }

        .price{

            margin: 0 10px 14px;

            text-align: center;

            color: #ff6700;

        }


    </style>

</head>

<body>

    <div class="exhibit">

        <div class="left">

            <img src="./images/1.webp" alt="1" class="ex">

        </div>

        <div class="right">

            <div class="box">

                <img src="./images/2.webp" alt="1" class="sal">

                <h3 class="title">Redmi Note 11 5G</h3>

                <p class="desc">5000mAh大电量</p>

                <p class="price">1119元</p>


            </div>

            <div class="box">

                <img src="./images/2.webp" alt="1" class="sal">

                <h3 class="title">Redmi Note 11 5G</h3>

                <p class="desc">5000mAh大电量</p>

                <p class="price">1119元</p>

            </div>

            <div class="box">

                <img src="./images/2.webp" alt="1" class="sal">

                <h3 class="title">Redmi Note 11 5G</h3>

                <p class="desc">5000mAh大电量</p>

                <p class="price">1119元</p>

            </div>

            <div class="box">

                <img src="./images/2.webp" alt="1" class="sal">

                <h3 class="title">Redmi Note 11 5G</h3>

                <p class="desc">5000mAh大电量</p>

                <p class="price">1119元</p>

            </div>

            <div class="box">

                <img src="./images/2.webp" alt="1" class="sal">

                <h3 class="title">Redmi Note 11 5G</h3>

                <p class="desc">5000mAh大电量</p>

                <p class="price">1119元</p>

            </div>

            <div class="box">

                <img src="./images/2.webp" alt="1" class="sal">

                <h3 class="title">Redmi Note 11 5G</h3>

                <p class="desc">5000mAh大电量</p>

                <p class="price">1119元</p>

            </div>

            <div class="box">

                <img src="./images/2.webp" alt="1" class="sal">

                <h3 class="title">Redmi Note 11 5G</h3>

                <p class="desc">5000mAh大电量</p>

                <p class="price">1119元</p>

            </div>

            <div class="box">

                <img src="./images/2.webp" alt="1" class="sal">

                <h3 class="title">Redmi Note 11 5G</h3>

                <p class="desc">5000mAh大电量</p>

                <p class="price">1119元</p>

            </div>

        </div>

    </div>

</body>

</html>

image.png

WEB前端全系列/第一阶段:HTML5+CSS3模块/初识CSS 163楼

<style>
        body {
            background-color: #f1f1f1;
        }

        .phone {
            width: 1300px;
            height: 680px;
            margin: 0 auto;
        }

        .left {
            float: left;
            width: 234px;
            height: 680px;
            margin-top: 10px;
            background-color: pink;
        }

        .right {
            float: right;
            width: 1050px;
        }

        .item {
            width: 250px;
            height: 335px;
            float: left;
            margin-left: 10px;
            background-color: rgb(215, 212, 212);
            margin-top: 10px;
            text-align: center;
        }
        .left img {
            width: 234px;
            height: 680px;
        }
        .right img {
            width: 220px;
            height: 220px;
        }
    </style>

</head>

<body>
    <div class="phone">
        <div class="left">
            <img src="./images/1.webp">
        </div>
        <div class="right">
            <div class="item">
                <img src="./images/2.webp">
                <h3>黑鲨4S</h3>
                <p>磁动力升降肩键</p>
            </div>
            <div class="item">
                <img src="./images/2.webp">
                <h3>黑鲨4S</h3>
                <p>磁动力升降肩键</p>
            </div>
            <div class="item">
                <img src="./images/2.webp">
                <h3>黑鲨4S</h3>
                <p>磁动力升降肩键</p>
            </div>
            <div class="item">
                <img src="./images/2.webp">
                <h3>黑鲨4S</h3>
                <p>磁动力升降肩键</p>
            </div>
            <div class="item">
                <img src="./images/2.webp">
                <h3>黑鲨4S</h3>
                <p>磁动力升降肩键</p>
            </div>
            <div class="item">
                <img src="./images/2.webp">
                <h3>黑鲨4S</h3>
                <p>磁动力升降肩键</p>
            </div>
            <div class="item">
                <img src="./images/2.webp">
                <h3>黑鲨4S</h3>
                <p>磁动力升降肩键</p>
            </div>
            <div class="item">
                <img src="./images/2.webp">
                <h3>黑鲨4S</h3>
                <p>磁动力升降肩键</p>
            </div>
        </div>
    </div>
</body>

image.png

WEB前端全系列/第一阶段:HTML5+CSS3模块/初识CSS 164楼

<style>
        .box {
            width: 300px;
            height: 300px;
        }

        .left {
            float: left;
            width: 100px;
            height: 300px;
            background-color: rgb(209, 106, 106);
        }

        .right {
            float: right;
            width: 200px;
            height: 150px;
        }

        .top {
            float: top;
            width: 200px;
            height: 150px;
            background-color: skyblue;
        }

        .bottom {
            float: bottom;
            width: 200px;
            height: 150px;
        }

        .b-left {
            float: left;
            width: 100px;
            height: 150px;
            background-color: blue;
        }
        .b-right {
            float: right;
            width: 100px;
            height: 150px;
            background-color: rgb(44, 191, 183);
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="left"></div>
        <div class="right">
            <div class="top"></div>
            <div class="bottom">
                <div class="b-left"></div>
                <div class="b-right"></div>
            </div>
        </div>
    </div>
</body>

image.png

WEB前端全系列/第一阶段:HTML5+CSS3模块/初识CSS 165楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637