会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132358个问题

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        a{
            text-decoration: none;
        }
        .box,.box1{
            width: 303px;
            height: 375px;
            background-color: red;
            position: relative;
        }
        .box1{
            float:left;
        }
         img{
            width: 100%;
        }
        .text{
            width: 100%;
            height: 88px;
            /*相对于已经定位的父元素定位*/
            position: absolute;
            left: 0;
            bottom: 20px;
            text-align: center;

        }
        .name{
            color: #fff;
            font-size: 21px;
            font-weight: 700;
        }
        .desc{
            color: #fff;
            font-size: 14px;
        }
        .price{
            color: #ebce6b;
            font-size: 24px;
            font-weight: 700;
        }
    </style>
</head>
<body>
<div class="box">
    <a href="#">
        <img src="images/370ad36f-425c-453a-b406-ccb2a0dffeec.jpg" alt="">
        <div class="text">
            <p class="name">MEIZU UR 高端定制耳机 预约</p>
            <p class="desc">【预约专用】私人定制,为你而声</p>
            <p class="price">¥200</p>
        </div>
    </a>
</div>
<div class="box1">
    <a href="#">
        <img src="images/370ad36f-425c-453a-b406-ccb2a0dffeec.jpg" alt="">
        <div class="text">
            <p class="name">MEIZU UR 高端定制耳机 预约</p>
            <p class="desc">【预约专用】私人定制,为你而声</p>
            <p class="price">¥200</p>
        </div>
    </a>
</div>
</body>
</html>

我已经在box1处加了float:left;效果图为什么没有实现块级元素水平显示

WEB前端全系列/第一阶段:HTML5+CSS3模块/CSS常用属性 211楼
WEB前端全系列/第一阶段:HTML5+CSS3模块/浮动与定位 214楼

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>利用定位知识点</title>
    <style>
        * {
            /*p默认有16px的上下外边距*/
            margin: 0px;
        }
    .box{
        position:relative;
        width: 100%;
        height: 1155px;
    }
   .box img{
       width:100%;
   }
        .box1,.box2{
           width:303px;
           height:375px;
           background-color: red;
           position:absolute;
           top: 10px;
           left: 10px;
           right: 10px;
           /*position:static;使用静态定位,就相对浏览页面*/
       }


        a{
            text-decoration:none;
        }
        .box1,.box2{
            position:relative;
        }
        .text1,.text2{
            width:303px;
            height:88px;
            position:absolute;
            left:0px;
            bottom:20px;
            text-align:center;
        }
        .name1{
            color: #fff;
            font-size: 21px;
            font-weight: 700;
        }
        .desc1{
            color:#fff;
            font-size:14px;
        }
        .price1{
            color: #ebce6b;
            font-size: 24px;
            font-weight: 700;
        }
        .box2{
            background-color: whitesmoke;

        }

        .name2{
            color: #333;
            font-size: 16px;
        }
        .desc2{
            color:#999;
            font-size: 14px;
        }
        .price2{
            color: #ebce6b;
            font-size: 24px;
            font-weight: 700;
        }
        .box2 span{
            color:#cc0000;
            font-size: 14px;
        }
        .box2 .number{
            color:#cc0000;
            font-size: 22px;
        }
        s{
            color:gray;
            font-size: 14px;
        }
    </style>
</head>
<body>
<div class="box">
    <div class="box1">
        <a href="#">
            <img src="images/1.jpg" alt="">
            <div class="text1">
                <p class="name1">魅族 EP3C 耳机</p>
                <p class="desc1">【限时特惠99元】</p>
                <p class="price1">¥129</p>
            </div>
        </a>
    </div>
    <div class=" box2">
        <a href="#">
            <img src="images/2.png" alt="">
            <div class="text2 ">
                <p class="name2">魅族 POP Pro 主动降噪耳机</p>
                <p class="desc2">三重混合主动降噪技术 | 三麦克风智能通话降噪</p>
                <p class="price2"><span>¥</span><span class="number">499</span></p>
            </div>
        </a>
    </div>
    <div class=" box2">
        <a href="#">
            <img src="images/3.png" alt="">
            <div class="text2 ">
                <p class="name2">魅族 POP2s 真无线耳机</p>
                <p class="desc2">【限时6期免息】好声音标杆 | Flyme 妙连</p>
                <p class="price2"><span>¥</span><span class="number">299</span></p>
            </div>
        </a>
    </div>
    <div class=" box2">
        <a href="#">
            <img src="images/4.png" alt="">
            <div class="text2 ">
                <p class="name2">魅族 HIFI 解码耳放</p>
                <p class="desc2">【年货节特惠价149元】</p>
                <p class="price2"><span>¥</span><span class="number">169</span></p>
            </div>
        </a>
    </div>
    <div class=" box2">
        <a href="#">
            <img src="images/5.jpg" alt="">
            <div class="text2 ">
                <p class="name1">魅族 HD60 头戴式蓝牙耳机</p>
                <p class="desc1">【年货节特惠价349元+12期免息】</p>
                <p class="price1">¥499</p>
            </div>
        </a>
    </div>
    <div class=" box2">
        <a href="#">
            <img src="images/6.png" alt="">
            <div class="text2 ">
                <p class="name2">魅族 HD60 降噪耳机</p>
                <p class="desc2">【年货节特惠价799元+12期免息】</p>
                <p class="price2"><span>¥</span><span class="number">1099</span></p>
            </div>
        </a>
    </div>
    <div class=" box2">
        <a href="#">
            <img src="images/7.png" alt="">
            <div class="text2 ">
                <p class="name2">魅族 EP63NC 无线降噪耳机</p>
                <p class="desc2">【年货节特惠价249元+6期免息】</p>
                <p class="price2"><span>¥</span><span class="number">249</span><s>¥499</s></p>
            </div>
        </a>
    </div>
    <div class=" box2">
        <a href="#">
            <img src="images/8.png" alt="">
            <div class="text2 ">
                <p class="name2">魅族 POP Pro 主动降噪耳机</p>
                <p class="desc2">【年货节特惠价149元】</p>
                <p class="price2"><span>¥</span><span class="number">149</span><s>¥169</s></p>
            </div>
        </a>
    </div>
</div>
</body>
</html>

这个我用定位的知识,父元素用了相对定位,8个div子元素用绝对定位,但效果图没有实现,水平显示。我想实现以下效果图。

blob.png

WEB前端全系列/第一阶段:HTML5+CSS3模块/CSS常用属性 220楼
WEB前端全系列/第一阶段:HTML5+CSS3模块/商城官网项目 221楼
WEB前端全系列/第一阶段:HTML5+CSS3模块/表单 223楼

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    .phone {
        width: 1300px;
        height: 680px;
        margin: 0 auto;
        background-color: bisque;
    }

    .left {
        width: 234px;
        height: 680px;
        background-color: rgb(236, 41, 7);
    }

    .right {
        float: right;
        width: 1050;
        height: 680px;
        background-color: aliceblue;
    }

    .box {
        float: left;
        width: 250px;
        height: 300px;
        background-color: black;
        margin-top: 10px;
        margin-left: 10px;
    }
</style>

<body>
    <div class="phone">
        <div class="left"></div>
        <div class="right">
            <div class="box"></div>
            <div class="box"></div>
            <div class="box"></div>
            <div class="box"></div>
            <div class="box"></div>
            <div class="box"></div>
            <div class="box"></div>
            <div class="box"></div>
        </div>
    </div>
</body>

</html>

老師,我的網頁加載后right裏面内容都向下排列了

WEB前端全系列/第一阶段:HTML5+CSS3模块/表单 224楼
WEB前端全系列/第一阶段:HTML5+CSS3模块/HTML5基础元素 225楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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