加入购物车按钮没法居中

来源:5-2 编程练习

回忆的

2017-10-17 18:38:57

<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <title></title>

    <style>

*{

  padding:0;

  margin:0;

}

    header {

        display:flex;

        justify-content:center;

        align-items:center;

background: #000;

        color: #FFF;

font-size:30px;

    }

div:nth-child(1) {

    display:flex;

        justify-content:center;

width:30%;

}

      ul {

          display:flex;

          justify-content:space-around;

  width:50%;   

  list-style-type:none;

      }

  div.login {

    display:flex;

        justify-content:center;

width:20%;

margin-left:10px;

}

div.login input{

    background: orange;

margin:auto 10px;

color:#FFF;

border: none;

font-size:30px;

}

section {

background:#abcdef;

width:40%;

display:flex;

}

section div.box{

height:100px;

justify-content:center;

align-items:center;

width:60%;

flex-direction:column;

}

section div.btn{

background:red;

height:100px;

width:40%;

    justify-content:center;

}

    </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="box">

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

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

<p>费用:550元</p>

   </div>

   <div class="btn">

     <p>加入购物车</p>

   </div>

   </section>

</body>

</html>

老师,我“加入购物车”那几个字不知道为什么没法居中

写回答

3回答

樱桃小胖子

2017-10-18

根据你的代码观察发现你的代码缺少样式,即:

http://img1.sycdn.imooc.com/climg/59e6bb030001f4d008070166.jpg

祝学习愉快~

0

回忆的

提问者

2017-10-18

嗯嗯,谢谢老师,这个方法确实可以;但是为什么我用flex语句都起不到效果呢?

justify-content:center;

align-items:center;

就是加了这两句,“加入购物车”那几个字都不动,完全不起作用,不知道为什么失效了

0

Miss路

2017-10-17

   text-align: center;

   line-height: 100px;

在section div.btn中加上这两句就能居中。行高=高度能够实现垂直居中,祝学习愉快!

0

0 学习 · 5012 问题

查看课程