老师,我的代码中,为什么缩小屏幕,section项目不会缩小,最终垂直排列了

来源:3-19 媒体查询-基础(2)

saltedfishman

2020-10-29 16:34:06

<!DOCTYPE html>

<html>


<head>

    <meta charset="UTF-8">

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

    <title></title>

    <style>

        * {

            margin0;

            padding0;

            list-stylenone;

        }

        @media screen and (min-width1200px)and (max-width2000px) {

            body {

                backgroundgreen;

            }

        } 

        

        header {

            colorwhite;

            background-colorblack;

            displayflex;

            justify-contentspace-around;

        }


        header .nav {

            displayflex;

            align-itemscenter;

            width400px;

            justify-contentspace-between;

            font-size30px;

        }


        header .login {

            width150px;

            displayflex;

            align-itemscenter;

            justify-contentspace-between;

        }

        header .login input {

            width60px;

            height35px;

            background-colororange;

            border-radius5px;

            bordernone;

            font-size20px;

            colorwhite;

        }


        section {

            displayflex;

            flex-wrapwrap;

            justify-contentspace-around;

            align-contentspace-around;

            height300px;

            background-colorgray;

        }

        section .section {

            background-colorskyblue;

            width425px;

            height110px;

            border-radius10px;

            displayflex;

            justify-contentspace-around;

            align-itemscenter;

            font-weightbold;

        }

        section .section .box {

            font-size15px;

            line-height25px;

        }

        section .section .shopping {

            background-colororange;

            width120px;

            height60px;

            font-size20px;

            line-height60px;

            text-aligncenter;

            colorwhite;

            font-weightbold;

            border-radius12px;

        }


    </style>

</head>


<body>

    <!-- 头部 -->

    <header>

        <div class="logo">

            <img src="http://climg.mukewang.com/59197ab000014f1503000100.jpg" alt="">

        </div>

        <ul class="nav">

            <li>课程</li>

            <li>路径</li>

            <li>猿问</li>

            <li>手记</li>

        </ul>

        <div class="login">

            <input type="button" value="登录">

            <input type="button" value="注册">

        </div>

    </header>

    <!-- 主体内容 -->

    <section>

        <div class="section">

            <div class="box">

                <p>《前端小白入门手册》</p>

                <div>适用人群:没有任何前端基础的小白</div>

                <div>费用:¥499</div>

            </div>

            <div class="shopping">

                <div class="btn">加入购物车</div>

            </div>

        </div>

        <div class="section">

            <div class="box">

                <p>《HTML5月CSS3实现动态网页》</p>

                <div>适用人群:有html和css基础的童鞋</div>

                <div>费用:¥599</div>

            </div>

            <div class="shopping">

                <div class="btn">加入购物车</div>

            </div>

        </div>

        <div class="section">

            <div class="box">

                <p>《HTML5月CSS3实现动态网页》</p>

                <div>适用人群:有html和css基础的童鞋</div>

                <div>费用:¥599</div>

            </div>

            <div class="shopping">

                <div class="btn">加入购物车</div>

            </div>

        </div>

        <div class="section">

            <div class="box">

                <p>《HTML5月CSS3实现动态网页》</p>

                <div>适用人群:有html和css基础的童鞋</div>

                <div>费用:¥599</div>

            </div>

            <div class="shopping">

                <div class="btn">加入购物车</div>

            </div>

        </div>

    </section>

    <script>


    </script>

</body>


</html>


在这里输入代码,可通过选择【代码语言】突出显示

写回答

1回答

好帮手慕鹤

2020-10-29

同学你好,出现问题的原因是:section容器设置的固定的宽度,当一行的宽度排不下两个section容器的时候,就变成了垂直效果,建议给section设置百分比的宽度,例如40%。

http://img.mukewang.com/climg/5f9a8faf091e4af904800290.jpg

建议同学给body设置一个最小宽度,当浏览器缩小到这个宽度的时候,页面内容就不再发生改变,参考如下:

http://img.mukewang.com/climg/5f9a9099095b172b03320081.jpg

祝学习愉快!

0

0 学习 · 15276 问题

查看课程