网格布局了解 grid
术语
网格线 grid lines:编号,命名
轨道 grid tracks:两条网格线间的区域,fr,%,px,auto-fill
单元格 grid cell:四条网格线包起来的区域
网格区域 grid area:多个单元格形成的区域
网格间距 grid gap:行或列之间的间隙
容器属性
grid-template-columns:定义网格列大小,
如:grid-template-columns: 1fr 1fr;
grid-template-rows 定义网格行大小
如:grid-template-rows: 300px 300px;
grid-template-areas 网格命名
如 grid-template-areas: “link list” “car test” “music .”;
“.”占位作用
grid-gap 网格间隙
grid-column-gap 列间隙
grid-row-gap 行间隙
grid-gap 行列间隙合并写,顺序先行后列
元素属性
grid-row-start/end grid-cloumn-start/end 将元素放入网格起止线之间的单元格
简写 grid-row: 起/止; grid-column: 起/止; 再简写 grid-area: 行起/列起/行止/列止;
grid布局实现
二手商品交易
效果图
html代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<link rel="stylesheet" href="grid_test.css" />
<title>二手商品交易</title>
</head>
<body>
<div class="public_headline">
<span>二手交易</span>
</div>
<!-- 二手交易区 -->
<div class="public_second_hand">
<!-- 标题1 -->
<div class="title1">
<a href="">抢好货</a>
<span>0低价, 便捷,安全,快速</span>
</div>
<!-- 标题2 -->
<div class="title2">
<span>热门分类</span>
<a href="">分类1</a>
<a href="">分类2</a>
<a href="">分类3</a>
<a href="">分类4</a>
<a href="">分类5</a>
</div>
<!-- 商品展示区 -->
<div class="goods">
<!-- 左侧商品列表 -->
<div class="goods-list">
<!-- 商品简介 -->
<div class="intro">
<a href="">
<img src="static/images/shop/shop3.jpg" alt="" width="176" height="120" />
</a>
<a href="">美女性感写真海报墙艺术装饰画贴画图</a>
<div>
<span>¥ 888</span>
<span>美女</span>
</div>
</div>
<div class="intro">
<a href=""><img src="static/images/shop/shop2.jpg" alt="" width="176" height="120" /></a>
<a href="">美女性感写真海报墙艺术装饰画贴画图</a>
<div>
<span>¥ 888</span>
<span>美女</span>
</div>
</div>
<div class="intro">
<a href=""><img src="static/images/shop/shop3.jpg" alt="" width="176" height="120" /></a>
<a href="">美女性感写真海报墙艺术装饰画贴画图</a>
<div>
<span>¥ 888</span>
<span>美女</span>
</div>
</div>
<div class="intro">
<a href=""><img src="static/images/shop/shop6.jpg" alt="" width="176" height="120" /></a>
<a href="">美女性感写真海报墙艺术装饰画贴画图</a>
<div>
<span>¥ 888</span>
<span>美女</span>
</div>
</div>
<div class="intro">
<a href=""><img src="static/images/shop/shop3.jpg" alt="" width="176" height="120" /></a>
<a href="">美女性感写真海报墙艺术装饰画贴画图</a>
<div>
<span>¥ 888</span>
<span>美女</span>
</div>
</div>
<div class="intro">
<a href=""><img src="static/images/shop/shop8.jpg" alt="" width="176" height="120" /></a>
<a href="">美女性感写真海报墙艺术装饰画贴画图</a>
<div>
<span>¥ 888</span>
<span>美女</span>
</div>
</div>
<div class="intro">
<a href=""><img src="static/images/shop/shop6.jpg" alt="" width="176" height="120" /></a>
<a href="">美女性感写真海报墙艺术装饰画贴画图</a>
<div>
<span>¥ 888</span>
<span>美女</span>
</div>
</div>
<div class="intro">
<a href=""><img src="static/images/shop/shop7.jpg" alt="" width="176" height="120" /></a>
<a href="">美女性感写真海报墙艺术装饰画贴画图</a>
<div>
<span>¥ 888</span>
<span>美女</span>
</div>
</div>
</div>
<!-- 右侧快速入口 -->
<div class="quick-entry">
<div class="quick-1">
<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>
<div class="quick-2">
<a href=""><img src="static/images/ad/image.png" alt="" /></a>
<a href=""><img src="static/images/ad/ad2.jpg" alt="" /></a>
</div>
</div>
</div>
</div>
</body>
</html>
css样式
/* 导入公共初始化样式 */
@import "public_reset.css";
.public_headline {
padding: 20px;
text-align: center;
}
.public_headline span {
font-size: 24px;
font-weight: bold;
margin-bottom: 10px;
border-bottom: 4px solid red;
}
/* 商品 */
.public_second_hand {
width: 1200px;
padding: 10px;
box-sizing: border-box;
margin: auto;
border: 1px solid #cccccc;
border-radius: 5px;
}
.public_second_hand:hover {
box-shadow: 0 0 10px #cccccc;
}
.public_second_hand > .title1 {
height: 50px;
border-bottom: 1px solid #cccccc;
}
/* 标题1 */
.public_second_hand > .title1 > a {
font-size: 24px;
margin-right: 15px;
}
.public_second_hand > .title1 > span {
color: red;
}
/* 标题2 */
.public_second_hand > .title2 {
height: 50px;
}
.public_second_hand > .title2 > span {
font-size: 24px;
color: red;
}
.public_second_hand > .title2 > a {
padding-left: 15px;
}
/* 商品列表 */
.public_second_hand > .goods {
display: grid;
grid-template-columns: 2fr 1fr;
grid-template-rows: auto;
grid-gap: 10px;
}
.public_second_hand > .goods > .goods-list {
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-template-rows: repeat(2, 1fr);
grid-gap: 10px;
}
.public_second_hand > .goods > .quick-entry {
display: grid;
grid-template-columns: 1fr;
grid-template-rows: 2fr 1fr;
grid-gap: 10px;
}
.public_second_hand > .goods > .quick-entry > .quick-1 {
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-template-rows: repeat(2, 1fr);
grid-gap: 10px;
}
.public_second_hand > .goods > .goods-list > .intro {
display: flex;
flex-flow: column nowrap;
justify-content: space-between;
}
.public_second_hand > .goods > .goods-list > .intro img {
border: 1px solid #cccccc;
border-radius: 5px;
}
.public_second_hand > .goods > .goods-list > .intro > div {
display: flex;
}
.public_second_hand > .goods > .goods-list > .intro > div > span:first-child {
color: red;
}
.public_second_hand > .goods > .goods-list > .intro > div > span:last-child {
color: #ffffff;
background-color: #55ce9f;
padding: 0 5px;
margin-left: auto;
}
.public_second_hand > .goods > .quick-entry > .quick-2 {
display: flex;
flex-flow: column nowrap;
justify-content: space-between;
}