布局还是有问题,不太熟练,主要是思路很乱,

来源:3-17 编程练习

慕村8326374

2021-05-16 14:49:10

能提供一些布局思路吗,具体运用那些布局属性,或者说老师的布局范例写一下,主要看一下每个步骤的注释思路,具体在某个环节运用某个属性,这个属性目的是什么?






​<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <title></title>

    <style>

      *{

        margin0;

        padding0;

        list-style-typenone;

      }

     header{

       width100%;

       displayflex;

       justify-contentspace-around;

       align-itemscenter;

       background-color:black;

       color#fff;

     }

     .nav{

      displayflex;

      justify-contentspace-between;

     width200px;

     }

     .login{

       displayflex;

       justify-contentspace-between;

       width100px;

     }

     input{

      background-color:rgba(2551650);

      colorwhite;

      bordernone;

      border-radius3px;

      padding5px;

     }

     section{

       display:inline-flex;

       width100%;

        justify-content:space-around;

        align-contentspace-between;

        padding30px;

        flex-wrapwrap;

      

     }

     .section{

       height150px;

       flex-basis700px;

       padding5px;

       background-color#ADD8E6;

       displayinline-flex;

       border-radius5px;

       margin5px;

       align-itemscenter;

       justify-contentspace-around;

     }

     .box{

       height100%;

       displayinline-flex;

       justify-contentspace-around;

       flex-directioncolumn;

     

     

     }

     .box p ,.box div{

       flex1;

       displayflex;

      

       align-itemscenter;

     }

     .shopping .btn{

      padding:5px ;

      backgroundorange;

      colorwhite;

      border-radius5px;


     }

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

同学你好,问题解答如下:

1、代码布局是可以的,但是水平方向上出现了滚动条

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

这是因为section设置宽度为100%后,还是设置了左右的padding增大

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

建议去掉左右的值

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

2、优化:

  • logo图与父元素之间出现间隙

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

    这是因为图片为行内元素,有文字特性,默认存在间隙。建议设置为块元素

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

  • 顶部中间导航建议设置宽度更大一点,分散些比较美观

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

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

  • 内容中每一个div.section盒子设置基础宽度为700px,建议修改为百分比,这样即使视口宽度小一些,也能一行两个显示

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

  • 每个小盒子中按钮没有对齐

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

    这是因为左侧内容长短不一,建议给内容盒子div.box设置宽度

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

3、同学这样布局是可以的,没问题。样式实现有很多种,并不会唯一,所以老师也没有范例。同学刚学习完flex就来写样式,不熟悉是很正常的,多练习就好了,不要着急哦。

祝学习愉快!

1

0 学习 · 15276 问题

查看课程