老师,请帮忙看看以下代码

来源:6-1 课程总结

慕尼黑4757019

2018-11-20 00:13:31

为什么.box里面的设置垂直方向为主轴,然后设置了主轴是居中,打开页面看到的效果是第一行的文字和其他行文字之间的间隙不一样呢?

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
    <style>
     header{
         width:1000px;
         height:auto;
         margin:auto;
         background:black;
         display:flex;
         justify-content:space-around;
         align-items:center;
     }
     .logo img{
         width:100px;
         height:50px;
     }
     li{
         list-style:none;
         width:90px;
         color:white;
     }
     header>ul{
         display:flex;
     }
     header>.login{
         display:flex;
         width:100px;
         justify-content:space-between;
     }
  input:hover{
         background:orange;
         color:white;
     }
     section{
         width:1000px;
         margin:auto;
         margin-top:10px;
         display:flex;
         justify-content:space-around;

     }
     .section{
         width:450px;
         display:flex;
         align-items:center;
         justify-content:space-between;
         background:#abcdef;
         padding:15px;
     }
     .box{
         display:flex;
         flex-direction:column;
         justify-content:center;
    }

    .btn:hover{
        background:orange;
        color:white;
        width:80px;
        height:40px;
        text-align:center;
        line-height:40px;
        font-size:14px;
    }
    </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>
    </section>  
</body>
</html>

写回答

1回答

好帮手慕星星

2018-11-20

p标签有默认的上下margin值,为16px,如下:

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

所以间隙会不一样。开始可以使用通配符将内外边距都去掉:

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

自己完善测试下。

祝学习愉快!

0

0 学习 · 5012 问题

查看课程