1.效果图
2.设计思路
2.1分析示意图
2.2flex布局分析
作业要求为用flex来实现页面效果,flex是弹性容器,特点是具有主轴和交叉轴,项目可以按轴排列。
第一步:合并同类项,由外至内依次划分出不同的弹性容器。
这个组件从外至内大概分为红、蓝、黄、绿四级弹性容器。
按照红色容器的排布来看,是纵向排列,因此其父级容器应该是垂直不换行。
标题行与文字导航区结构相似,里面的内容按样式均可分为两块,为了便于控制,设置span标签。左右间距可以通过margin或者padding来实现,如果用了padding的方法,需要加设box-size来控制盒子尺寸。
最下面的两个蓝色容器呈现左右分区的特点,因此其父级容器设置主轴为横向不换行。
底部左边蓝色区块,平均分布着8个样式相同的绿色区块,因此该容器可以设置为横向换行。其中每个绿色区块还可以细化为图片、介绍和价格标签三块,上中下分布。
底部右边蓝色区块内部,呈现出上下两类的特点,可以将上下两部分成两个容器。
第二步:确定页面尺寸,字体大小、图片大小、容器大小
第三步:按照从上至下,从左往右,依次写出页面的DOM结构
第四步:按照同样的次序写出css样式,同步观察调整
3.页面源码
3.1HTML代码:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="public_second_hand.css">
<title>public_second_hand</title>
</head>
<body>
<div class="public-headline">
<span>二手交易</span>
</div>
<div class="public-second-hand">
<div class="title1">
<a href="">抢好货</a>
<span>0低价,便捷,安全,快速</span>
</div>
<div class="title2">
<span>热门分类</span>
<a href="">美女写真</a>
<a href="">日本美女</a>
<a href="">美国美女</a>
<a href="">国内美女</a>
<a href="">AV美女</a>
</div>
<div class="goods">
<div class="goods-list">
<div class="img-info">
<a href=""><img src="../../static/images/shop/shop1.jpg" alt=""></a>
<a href="">美女性感写真海报墙艺术装饰画贴画图</a>
<div>
<span>¥ 333</span>
<span>美女</span>
</div>
</div>
<div class="img-info">
<a href=""><img src="../../static/images/shop/shop2.jpg" alt=""></a>
<a href="">美女性感写真海报墙艺术装饰画贴画图2</a>
<div>
<span>¥ 333</span>
<span>美女</span>
</div>
</div>
<div class="img-info">
<a href=""><img src="../../static/images/shop/shop3.jpg" alt="" ></a>
<a href="">美女性感写真海报墙艺术装饰画贴画图3</a>
<div>
<span>¥ 333</span>
<span>美女</span>
</div>
</div>
<div class="img-info">
<a href=""><img src="../../static/images/shop/shop4.jpg" alt="" ></a>
<a href="">美女性感写真海报墙艺术装饰画贴画图4</a>
<div>
<span>¥ 333</span>
<span>美女</span>
</div>
</div>
<div class="img-info">
<a href=""><img src="../../static/images/shop/shop5.jpg" alt="" ></a>
<a href="">美女性感写真海报墙艺术装饰画贴画图5</a>
<div>
<span>¥ 333</span>
<span>美女</span>
</div>
</div>
<div class="img-info">
<a href=""><img src="../../static/images/shop/shop6.jpg" alt="" ></a>
<a href="">美女性感写真海报墙艺术装饰画贴画图6</a>
<div>
<span>¥ 333</span>
<span>美女</span>
</div>
</div>
<div class="img-info">
<a href=""><img src="../../static/images/shop/shop7.jpg" alt="" ></a>
<a href="">美女性感写真海报墙艺术装饰画贴画图7</a>
<div>
<span>¥ 333</span>
<span>美女</span>
</div>
</div>
<div class="img-info">
<a href=""><img src="../../static/images/shop/shop8.jpg" alt=""></a>
<a href="">美女性感写真海报墙艺术装饰画贴画图8</a>
<div>
<span>¥ 333</span>
<span>美女</span>
</div>
</div>
</div>
<div class="quick-entry">
<a href=""><img src="../../static/images/ad/1.png" alt=""></a>
<a href=""><img src="../../static/images/ad/2.png" alt=""></a>
<a href=""><img src="../../static/images/ad/3.png" alt=""></a>
<a href=""><img src="../../static/images/ad/4.png" alt=""></a>
<div>
<img src="../../static/images/ad/image.png" alt="">
<img src="../../static/images/ad/ad2.jpg" alt="">
</div>
</div>
</div>
</div>
</body>
</html>
3.2CSS样式
/*引入初始化样式表*/
@import "../reset.css";
@import "../public_headline/public_headline.css";
/*设置最外层div样式*/
.public-second-hand {
display: flex;
flex-flow: column nowrap;
width: 1200px;
margin:auto;
padding: 10px;
box-sizing: border-box;
border-radius: 5px;
background-color: #ffffff;
}
.public-second-hand:hover {
box-shadow: 0 0 5px;
}
/*设置标题1样式*/
.public-second-hand > .title1 {
height: 50px;
border-bottom: 1px solid #888888;
}
.public-second-hand>.title1 a{
font-size:23px;
margin-right: 20px;
}
.public-second-hand>.title1>span {
font-size: 13px;
color: red;
}
/*设置标题2样式*/
.public-second-hand > .title2 {
height: 55px;
}
.public-second-hand > .title2 > span {
font-size: 23px;
color: red;
}
.public-second-hand > .title2 > a {
padding-left: 20px;
}
/*设置商品展示区样式*/
.public-second-hand > .goods {
display: flex;
flex-flow: row nowrap;
height: 440px;
}
.public-second-hand > .goods > .goods-list {
padding: 10px;
display: flex;
flex-basis: 800px;
flex-flow: row wrap;
justify-content: space-between;
}
.public-second-hand > .goods > .goods-list .img-info {
display: flex;
flex-flow: column nowrap;
width: 178px;
height: 200px;
justify-content: space-between;
}
.public-second-hand > .goods >.goods-list >.img-info img {
width: 176px;
height: 120px ;
border-radius: 5px;
border: 1px solid rgb(204 204 204);
}
.public-second-hand > .goods >.goods-list >.img-info div {
display: flex;
justify-content: space-between;
}
.public-second-hand > .goods >.goods-list >.img-info span:first-of-type{
color: red;
}
.public-second-hand > .goods >.goods-list >.img-info span:last-of-type{
color: white;
background-color: lightseagreen;
padding:0 5px;
margin-left: auto;
}
/*设置快速入口样式,弹性盒子,因为父级元素是弹性容器,设置基础宽度400,容器内项目两端对齐,自动换行*/
.public-second-hand > .goods >.quick-entry {
display: flex;
flex-basis: 400px;
padding: 10px;
flex-flow: row wrap;
justify-content: space-between;
}
/*设置图片尺寸*/
.public-second-hand >.goods > .quick-entry img{
width: 190px;
height: 130px;
}
/*将容器设为弹性容器,纵向排列不换行,因为其同时是上一级的弹性项目,需要设置宽度*/
.public-second-hand >.goods > .quick-entry > div {
display: flex;
width: 400px;
flex-flow:column nowrap;
}
/*设置图片尺寸*/
.public-second-hand >.goods > .quick-entry > div img {
width: 393px;
height: 60px;
}
4.评论回复区的页面分析图与源码
4.1页面效果图
4.2页面分析图
4.3分析思路
基本思路与上个页面相同,需要注意的是:
“我要评论”不能用行内元素的标签,只能用块元素标签,因为要设置上面的那个分隔条。
文本区域可以设置为flex:1或者flex:auto或者flex-grow:1,让其自动扩展。
在弹性盒子嵌套时,思路要清晰注意两点,一是轴向,二是区分容器与项目。
4.4源码
html代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="../../static/font/iconfont.css">
<link rel="stylesheet" href="public_comment_reply.css">
<title>评论回复区</title>
</head>
<body>
<div class="public-comment-reply">
<div class="comment-title">
<h3>我要评论</h3>
<div class="comment">
<label for="comment-area" ><img src="../../static/images/user.png" alt=""></label>
<input type="textarea" class="comment-area" id="comment-area" name="comment-area">
</div>
<button class="submit" id="submit">发表评论</button>
</div>
<div class="reply">
<h3>最新回复</h3>
<div class="userreply">
<img src="../../static/images/user.png" alt="">
<div>
<span>用户昵称</span>
<span>留言内容:PHP中文网,是一个有温度,有思想的学习平台</span>
<div class="time">
<span>2019-12-12 15:34:23发表</span>
<span><i class="iconfont icon-dianzan"></i>回复</span>
</div>
</div>
</div>
<div class="userreply">
<img src="../../static/images/user.png" alt="">
<div>
<span>用户昵称</span>
<span>留言内容:PHP中文网,是一个有温度,有思想的学习平台</span>
<div class="time">
<span>2019-12-12 15:34:23发表</span>
<span><i class="iconfont icon-dianzan"></i>回复</span>
</div>
</div>
</div>
<div class="userreply">
<img src="../../static/images/user.png" alt="">
<div>
<span>用户昵称</span>
<span>留言内容:PHP中文网,是一个有温度,有思想的学习平台</span>
<div class="time">
<span>2019-12-12 15:34:23发表</span>
<span><i class="iconfont icon-dianzan"></i>回复</span>
</div>
</div>
</div>
<div class="userreply">
<img src="../../static/images/user.png" alt="">
<div>
<span>用户昵称</span>
<span>留言内容:PHP中文网,是一个有温度,有思想的学习平台</span>
<div class="time">
<span>2019-12-12 15:34:23发表</span>
<span><i class="iconfont icon-dianzan"></i>回复</span>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
CSS代码:
/*引入初始化样式*/
@import url(../reset.css);
/*将入口类设置为flex,纵向排列*/
.public-comment-reply{
display: flex;
flex-direction: column;
padding: 15px;
box-sizing: border-box;
}
/*将回复区设置为flex,纵向排列*/
.public-comment-reply > .comment-title {
display: flex;
flex-direction: column;
}
/*设置标题格式,此处不能用span,因为它是内联块,加上边沿时不能横向扩展到整个页面,用h3是块元素,加上边框可以扩展*/
.public-comment-reply > .comment-title > h3 {
border-top: 1px solid #cccccc;
padding: 20px 0;
box-sizing: border-box;
}
/*设置图像和文本框区域样式,弹性盒子,项目横向排列*/
.public-comment-reply > .comment-title > .comment {
display: flex;
padding: 10px;
}
/*设置图像格式,图片加上block可以去除下面的空白区*/
.public-comment-reply > .comment-title > .comment img{
width: 60px;
height: 60px;
border-radius: 5px;
justify-content: center;
display: block;
}
/*设置文本框样式,flex:1与flex:auto效果相同,可以自动增长宽度*/
.public-comment-reply > .comment-title > .comment .comment-area {
height: 200px;
margin-left: 20px;
flex: 1;
}
/*设置鼠标滑过文本框的样式*/
.public-comment-reply > .comment-title > .comment .comment-area:hover{
box-shadow:0 0 5px #cccccc;
}
/*设置按钮的样式,此时的主轴为纵轴,所以交叉轴为横轴,可以用align-self来将按钮安排在最右侧,
还可以用margin-left:auto的方法达到同样党的效果*/
.public-comment-reply > .comment-title > .submit {
font-size: 14px;
background-color: red;
color: white;
height: 40px;
width: 150px;
/*align-self: flex-end;*/
margin-left: auto;
border: none;
}
.public-comment-reply > .comment-title > .submit:hover {
background-color: #178cee;
}
/*设置评论区样式*/
.reply{
display: flex;
flex-direction: column;
}
.reply > div {
display: flex;
margin-top: 30px;
}
.reply img{
width: 60px;
height: 60px;
border-radius: 5px;
align-self: center;
display: block;
}
.reply > div > div{
display: flex;
flex: 1;
flex-direction: column;
margin-left: 20px;
height: 90px;
justify-content: space-between;
}
.reply > div > div >div {
display: flex;
justify-content: space-between;
}
/*将点赞图标设置颜色和大小,注意大小的单位*/
.reply > div > div i{
color: red;
font-size: 1rem;
}