布局还是有问题,不太熟练,主要是思路很乱,
来源:3-17 编程练习
慕村8326374
2021-05-16 14:49:10
能提供一些布局思路吗,具体运用那些布局属性,或者说老师的布局范例写一下,主要看一下每个步骤的注释思路,具体在某个环节运用某个属性,这个属性目的是什么?
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
*{
margin: 0;
padding: 0;
list-style-type: none;
}
header{
width: 100%;
display: flex;
justify-content: space-around;
align-items: center;
background-color:black;
color: #fff;
}
.nav{
display: flex;
justify-content: space-between;
width: 200px;
}
.login{
display: flex;
justify-content: space-between;
width: 100px;
}
input{
background-color:rgba(255, 165, 0);
color: white;
border: none;
border-radius: 3px;
padding: 5px;
}
section{
display:inline-flex;
width: 100%;
justify-content:space-around;
align-content: space-between;
padding: 30px;
flex-wrap: wrap;
}
.section{
height: 150px;
flex-basis: 700px;
padding: 5px;
background-color: #ADD8E6;
display: inline-flex;
border-radius: 5px;
margin: 5px;
align-items: center;
justify-content: space-around;
}
.box{
height: 100%;
display: inline-flex;
justify-content: space-around;
flex-direction: column;
}
.box p ,.box div{
flex: 1;
display: flex;
align-items: center;
}
.shopping .btn{
padding:5px ;
background: orange;
color: white;
border-radius: 5px;
}
</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、代码布局是可以的,但是水平方向上出现了滚动条

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

建议去掉左右的值

2、优化:
logo图与父元素之间出现间隙

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

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


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

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

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

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