老师 section不设置高的话 就会出现截图的情况 实际开发中应该不会把高度设死吧 那我的问题在哪里?

来源:3-17 编程练习

weixin_慕莱坞5016066

2021-04-15 23:03:31

<!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>

        *{

            margin0;

            padding0;


        }

        header{

            displayflex;

            background-colorblack;

            justify-contentspace-around;

            align-itemscenter;

        }

        .nav{

            displayflex;

            list-stylenone;

            colorwhite;

            justify-contentspace-between;

            font-size25px;

            width40%;

        }

        .login{

            width10%;

            displayflex;

            justify-contentspace-between;

        }

        .login input{

            background-colororange;

            font-size20px;

            bordernone;

            colorwhite;

            border-radius3px;

        }


        section{

            displayflex;

            flex-wrapwrap;

            /* height: 500px; */

            justify-content:space-around;

            align-contentspace-around;

        }

        .section{

            height200px;

            width45%;

            background-colorblue;

            border-radius5px;

            displayflex;

            justify-contentspace-around;

            

            

        }

        .section .box{

            displayflex;

            flex-directioncolumn;

            justify-contentspace-around;

            


        }

        .section .shopping{

            height18%;

            width20%;

            displayflex;

            background-colororange;

            colorwhite;

            border-radius3px;

            align-selfcenter;

            justify-contentspace-around;

            align-itemscenter;

        }

       

    </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>  

</body>

</html>

相关截图:

http://img.mukewang.com/climg/6078552e09dc458b18960609.jpg

写回答

1回答

好帮手慕久久

2021-04-16

同学你好,解答如下:

1、如果section中的内容是固定,那么就可以给section设置固定高。反之,section中的.section个数不确定,那么就不能设置固定高。

2、如果想让.section上下之间有间距,可以使用margin、padding来调整,如下:

http://img.mukewang.com/climg/6078f70f09ae9a8308680509.jpg

代码可做如下优化:

按钮文字紧挨父元素边缘,样式不好看,可以使用padding调整一下:

http://img.mukewang.com/climg/6078f7820967eece06230237.jpg

除此之外,代码没有其他问题。

祝学习愉快!


0

0 学习 · 15276 问题

查看课程