老师请检查代码,还有怎么实现文本左对齐

来源:3-17 编程练习

twtszz

2020-07-28 10:54:39

<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <title></title>

    <style>

     /* 在此处补充代码*/

*{

margin: 0;

padding: 0;

}

body{ 

display: flex;

flex-direction: column;

justify-content: center;

align-items: center;

}

 

     header{

         display:flex;

         justify-content:space-around;

 

background:black;

width: 100%;

margin-bottom: 16.6px;

     }

header .logo{

width: 30%;

display: flex;

align-items: center;

justify-content: center;

}

     header ul{

         display:flex;

         justify-content:space-around;

         align-items:center;

flex: 1;

 

list-style: none;

color: white;

     }

     header .login{

         display:flex;

         justify-content:center;

         align-items:center;

 

width: 20%;

     }

     header .login input{

         background-color: orange;

  color: white;

  border: none;

  border-radius: 2px;

  width: 40px;

  height: 20px;

  line-height: 20px;

  margin: 0 10px;

     }

 

section{

width:80%;

height:350px;

 

display: flex;

flex-wrap: wrap;

justify-content:space-around;

align-content: space-around;

}

 

.section{

background: skyblue;

width: 45%;

height: 150px;

border-radius: 5px;

 

display: flex;

justify-content: center;

align-content: space-around;

}

.section .box{

width: 65%;

 

display: flex;

flex-direction: column;

justify-content: space-around;

align-items: center;

}

.section .shopping{

width: 35%;

 

display: flex;

justify-content: center;

align-items: center;

}

.section .shopping .btn{

background: orange;

color: white;

  font-size: 16px;

width: 85px;

height: 40px;

line-height: 40px;

text-align: center;

border: none;

border-radius: 5px;

cursor:pointer;

}

 

.section .shopping .btn:hover{

color:green;

}

 

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


写回答

2回答

好帮手慕码

2020-07-28

同学你好,可以来分析一下:先把box中的样式都去掉:

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

可以看到,文字是左对齐的,这时候添加flex布局:

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

由于flex布局,p、div标签可以呈现内联块标签的形式,横着排列。这时候,添加flex-direction: column;,让内部标签垂直分布,可以类比为,主轴从红色箭头处移到了绿色箭头方向:http://img.mukewang.com/climg/5f1f9e8f09f0673007190605.jpg

最后,添加justify-content: space-around;。拉开每行的距离即可。

同学可以试着再理解一下,祝学习愉快~

1

好帮手慕码

2020-07-28

同学你好,其他实现的是可以的。实现文本左对齐,可以参考如下:

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

祝学习愉快~

0
hwtszz
h 老师不明白为什么这样就实现了文本左对齐
h020-07-28
共1条回复

0 学习 · 6815 问题

查看课程