老师我这里布局不是适应手机端的 当我把窗口调小了 文字就像这样溢出了 不在容器里了 我应该采用什么思路去布局呢
来源:3-17 编程练习
慕尼黑0510008
2022-03-17 15:40:49
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
ul {
list-style: none;
}
.logo,
.nav,
.login {
display: flex;
}
.logo img {
display: block;
}
.daohang {
width: 100%;
display: flex;
background-color: black;
align-items: center;
justify-content: space-around;
}
.nav {
color: aliceblue;
width: 500px;
justify-content: space-around;
}
.login {
width: 100px;
justify-content: space-around;
}
.login input {
background-color: yellow;
}
.zhuti {
width: 100%;
height: 300px;
display: flex;
flex-wrap: wrap;
justify-content: space-around;
}
.section {
width: 40%;
margin-top: 10px;
display: flex;
height: 120px;
background-color: aqua;
justify-content: space-around;
}
.box {
width: 75%;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.shopping {
display: flex;
justify-content: right;
align-items: center;
}
.btn {
width: 130px;
background-color: chartreuse;
text-align: center;
}
</style>
<body>
<div class="daohang">
<div class="logo">
<img src="http://climg.mukewang.com/59feb59700019dab01910057.png" 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>
</div>
<!-- 主体内容 -->
<section class="zhuti">
<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>《前端小白入门手册》</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回答
好帮手慕星星
2022-03-17
同学你好,代码优化如下:
1、body默认有外边距8px,这样页面四周会留白边,看着不美观
建议去掉元素默认边距
2、顶部右侧按钮,默认有边框,看着不美观
可以手动设置去掉边框,并添加padding内边距撑起来,圆角效果以及字体颜色为白色
3、每个列表项可以添加圆角效果,左侧的内容建议修改为space-around分布,这样上下还能留出一些间隙,右侧按钮也可以进行样式调整
4、视口变小后,文字不会变小,溢出是正常的。一般在移动端会有不同的布局方式,可能会变为一行一列显示,这样美观一些。目前可以不考虑移动端效果,会用flex即可。
祝学习愉快~
相似问题