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

/* 导航样式开始 */
.nav {
    width: 100%;
    height: 66px;
    background: #88c5e1;
    border-bottom: 5px solid #54abd4;
}

.wrap {
    width: 87%;
    margin: 0 auto;
}

.logo,
.nav-bar,
.search {
    float: left;
    height: 66px;
}


.search .text-input {
    width: 100%;
    height: 40px;
    background-color: #f5f5f5;
    border: 1px solid #f5f5f5;
    box-sizing: border-box;
    border-radius: 2px;
    outline: none;
    margin-top: 13px;
    padding-left: 10px;
    transition: all 0.2s;
}

.search button {
    width: 40px;
    height: 34px;
    background-color: #f5f5f5;
    color: #54abd4;
    font-weight: 900;
    position: absolute;
    top: 16px;
    right: 2px;
}

.text-input:hover {
    background-color: #f5f5f5;
    border-color: #54abd4;
}


.nav-bar>ul {
    float: right;
}

.nav-bar ul li {
    float: left;
}

.nav-bar ul li a {
    color: #fff;
    padding: 10px;
    display: block;
    margin-left: 8px;
    margin-top: 12.5px;
}

.nav-bar-active {
    border-bottom: 2px solid #fff;
}

.nav-bar a:hover {
    border-bottom: 2px solid #fff;
}

/* 导航样式结束 */

/* **************  响应式设计  *********** */
/* pc端 */
@media screen and(min-width:992px) {
    .logo {
        width: 25%;
        background: url("../images/Brand.png") no-repeat left;
        background-size: 183px;
    }

    .search {
        width: 40%;
        position: relative;
    }

    .nav-bar {
        width: 35%;
    }

    .btn {
        display: none;
    }
}

/* pad端 */
@media screen and(min-width:768px) and (max-width:992px) {
    .logo {
        width: 18%;
        background: url("../images/Brand-M.png") no-repeat left;
        background-size: 86px;
    }

    .search {
        width: 42%;
        position: relative;
    }

    .nav-bar {
        width: 40%;
    }

    .btn {
        display: none;
    }
}

/* M端 */
@media screen and(max-width:768px) {
    .logo {
        width: 16%;
        background: url("../images/Brand-S.png") no-repeat left;
        background-size: 38px;
    }

    .search {
        width: 68%;
        position: relative;
    }

    .nav-bar {
        display: none;
    }

    .btn {
        width: 43px;
        height: 43px;
        border: 1px solid #fff;
        font-weight: 700;
        line-height: 43px;
        float: right;
        color: #fff;
        margin-top: 10.5px;
    }

    .btn i {
        font-size: 20px;
    }
}

也不知道哪里出问题了,对照着源码对了好几遍了,但是源码复制过来就没问题了

image.png

WEB前端全系列/第一阶段:HTML5+CSS3模块/响应式项目 153楼
WEB前端全系列/第一阶段:HTML5+CSS3模块/HTML5基础元素 154楼
WEB前端全系列/第一阶段:HTML5+CSS3模块/商城官网项目 155楼
WEB前端全系列/第一阶段:HTML5+CSS3模块/商城官网项目 156楼
WEB前端全系列/第一阶段:HTML5+CSS3模块/CSS3新特性 163楼

嗷嗷刚刚代码那个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模块/浮动与定位 164楼

<!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模块/浮动与定位 165楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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