哪个布局更好点?或者哪个布局正确点?

来源:3-17 编程练习

要每天学习的小蓝同学

2021-08-24 16:54:39

相关代码:

相关代码:<style>
* {
padding: 0;
margin: 0;
}

/* 头部 */
.logo {
transform: scale(0.7);
}

header {
width: 100%;
height: 68px;
background-color: rgb(10, 10, 10);
display: flex;
justify-content: space-around;
align-items: center;
}

.nav {
width: 45%;
height: 100%;
list-style: none;
display: flex;
justify-content: space-around;
align-items: center;
font-size: 20px;
color: aliceblue;
}

.login {
width: 10%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
justify-content: space-around;
}

.login input {
transform: scale(1.4);
background-color: rgb(238, 184, 36);
color: rgb(246, 247, 248);
border: none;
border-radius: 3px;
}

/* 主题内容 */
section {
height: 400px;
width: 1100px;
margin: auto;
background-color: rgb(211, 208, 208);
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;
justify-content: space-around;
}
.section {
width: 500px;
height: 130px;
background-color: rgb(116, 221, 224);
display: flex;
justify-content: space-around;
align-items: center;
border-radius: 10px;
}
.box {
height: 100%;
display: flex;
flex-direction: column;
justify-content: space-around;
}
.btn {
width: 100px;
height: 40px;
background-color: rgb(225, 228, 60);
color: aliceblue;
font-weight: 600;
display: flex;
justify-content: center;
align-items: center;
border-radius: 10px;
cursor: pointer;
}
</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>

相关代码:

​ <style>
* {
padding: 0;
margin: 0;
}

/* 头部 */
.logo {
transform: scale(0.7);
}
header {
width: 100%;
height: 68px;
background-color: rgb(10, 10, 10);
display: flex;
justify-content: space-around;
align-items: center;
}
.nav {
width: 45%;
height: 100%;
list-style: none;
display: flex;
justify-content: space-around;
align-items: center;
font-size: 20px;
color: aliceblue;
}
.login {
width: 10%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
justify-content: space-around;
}
.login input {
transform: scale(1.4);
background-color: rgb(238, 184, 36);
color: rgb(246, 247, 248);
border: none;
border-radius: 3px;
}
/* 主题内容 */
section{
height: 350px;
width: 1100px;
margin: auto;
background-color: rgb(211, 208, 208);
display: flex;
flex-direction: column;
justify-content: space-around;
align-items: center;
}
.section-1{
display: flex;
width: 1050px;
justify-content: space-around;
}
.section {
width: 500px;
height: 130px;
background-color: rgb(116, 221, 224);
border-radius: 10px;
display: flex;
justify-content: space-around;
align-items: center;
}
.box {
height: 100%;
display: flex;
flex-direction: column;
justify-content: space-around;
}
.btn {
width: 100px;
height: 40px;
background-color: rgb(225, 228, 60);
color: aliceblue;
font-weight: 600;
display: flex;
justify-content: center;
align-items: center;
border-radius: 10px;
cursor: pointer;
}
</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-1">
<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>
<div class="section-1">
<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>
</div>
</section>
</body>

以上是课程的作业,不知道算不算按要求做了的

写回答

1回答

好帮手慕久久

2021-08-24

同学你好,解答如下:

第一种方案的布局更好些:主体中四组内容的样式、结构是一样的,都放在一个父元素中即可:

http://img.mukewang.com/climg/6124b5f009d33cc106330373.jpg

样式可做如下优化:

1、头部不用设置固定高度,让其高度由图片撑开即可,这样就不用缩放图片了:

http://img.mukewang.com/climg/6124b899099d4ca106830409.jpg

2、transform的兼容性不如width、padding......这些基础样式好,因此建议通过调整字体大小、添加padding等方式,将按钮大小、样式调整合适:

http://img.mukewang.com/climg/6124b76b09cc089e06960302.jpg

3、主体内容是全屏显示的,不是固定宽度。建议将宽度、高度等属性去掉:

http://img.mukewang.com/climg/6124b843094b0efe08240339.jpg

为了让一行显示2组内容,建议将每组内容的宽度设置成百分比:

http://img.mukewang.com/climg/6124b8600971973906760337.jpg

祝学习愉快!​


1

0 学习 · 15276 问题

查看课程