请问,这个布局里面,有没有无效的多余的布局步骤,或者说是有没有欠缺那些可以运用到的布局方式。

来源:3-17 编程练习

慕村8326374

2021-05-17 23:12:49

请问,这个布局里面,有没有无效的多余的布局步骤,或者说是有没有欠缺那些可以运用到的布局方式。

比如说在某个布局里面可以用更好的方式去运用布局,请老师看一下,改进一下,那些可以删掉,那些应该增加

<html>

<head>

    <meta charset="UTF-8">

    <title></title>

    <style>

        

        *{

            margin: 0;

            padding: 0;

            text-decoration: none;

            list-style-type: none;

        }   

    header{

        width: 100%;

        background: black;

        color: white;

        display: inline-flex;

        justify-content: space-around;

        align-items: center;

    }

    .logo img{

     display: block;

    }

    .nav{

       display: inline-flex;

        justify-content: space-between;

        width: 500px;

       font-size:30px;

      }

   input{

       border: none;


       padding: 10px;

       font-size: 20px;

       border-radius: 5px;

       color: white;

       background-color: orange;

       margin: 0 10px;

   }

   section{

       display: inline-flex;

       width: 100%;

       flex-wrap: wrap;

       justify-content: space-around;

  

   }

   

   .section{

       display: inline-flex;

       align-items: center;

       flex-basis: 40%;

       height: 150px;

       padding: 15px;

       background: skyblue;

       margin: 10px;

       border-radius: 15px;

    


       

   }

   .box{

       padding:20px;

       display: inline-flex;

       width: 70%;

       height: 100%;

       flex-direction: column;

       justify-content:space-between;

   }

   

  .shopping{

    padding:8px ;

    background-color:orange ;

    border-radius: 5px;

    color: white;

  }

    </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>《从H5网页开发到移动端响应式开发》</p>

    

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

    

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

    

        </div>

    

        <div class="shopping">

    

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

    

        </div>

    

    </div>

    

    <div class="section">

    

        <div class="box">

    

            <p>《从H5网页开发到移动端响应式开发》</p>

    

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

    

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

    

        </div>

    

        <div class="shopping">

    

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

    

        </div>

    

    </div>

    

    </section>

    </body>

    

    </html>



写回答

1回答

好帮手慕久久

2021-05-18

同学你好,代码可做如下优化:

 1、inline-flex是将元素转成内联块弹性盒子,此时盒子类似于行内块,其宽度由内容撑开,而flex会让盒子保持块级元素属性,宽度会占满父元素。因此对于header来讲,将其设置成flex即可(可以简化代码):

http://img.mukewang.com/climg/60a3245909fb6fed07150277.jpg

2、header设置display:flex后,它的子元素会在一行显示,此时.nav就没必要设置成inline-flex了,设置成flex就可以:

http://img.mukewang.com/climg/60a324d6098b8e0b06180215.jpg

以上两点是想告诉同学:

在flex布局中,更多的时候是使用display:flex;,很少使用inline-flex,所以同学可以将页面中所有的inline-flex都改成flex(最好使用大家都爱用的属性)。

3、如下结构,高度超出父元素:

http://img.mukewang.com/climg/60a325cd095f4f4d08220723.jpg


建议把.box的padding去除:

http://img.mukewang.com/climg/60a32601098452a706340230.jpg

祝学习愉快!

1

0 学习 · 15276 问题

查看课程