学习总结
- grid主要适用于布局大框架,而细节处理还是需要grid和flex配合进行
- 使用grid可以简化html和css文件中的代码量
- 下面代码还可以优化,二手交易在是用flex布局,可以用grid布局
1.仿整站首页
- 演示链接 仿老师的整站首页
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="../static/font/iconfont.css" />
<link rel="stylesheet" href="index.css" />
<title>全站首页</title>
</head>
<body>
<!-- 全站页眉 -->
<div class="public_header">
<a href="">网站首页</a>
<a href="">专题</a>
<a href="">网站导航</a>
<a href="">二手商品</a>
<a href="">讨论区</a>
<span>
<a href=""><label class="iconfont icon-huiyuan2"></label>登陆</a>
<a href="">免费注册</a>
</span>
</div>
<!-- 首页快速进入按钮、轮播图、搜索框 -->
<div class="index_header">
<div class="logo_search">
<!-- logo图标 -->
<div>
<a href=""><img src="../static/images/logo.png" alt="" /></a>
</div>
<!-- 搜索框 -->
<div>
<input type="search" name="search" id="search" />
<label for="search" class="iconfont icon-sousuo1"></label>
</div>
<!-- 字体图标 点赞 评论 下载 会员等 -->
<div>
<span class="iconfont icon-huiyuan1"></span>
<span class="iconfont icon-danmu1"></span>
<span class="iconfont icon-fabu"></span>
<span class="iconfont con-fangda"></span>
<span class="iconfont icon-huiyuan2"></span>
<span class="iconfont icon-dianzan"></span>
</div>
</div>
<div class="nav">
<div class="detail">
<div>
<span class="iconfont icon-gongdan"></span>
</div>
<div>
<p>资讯</p>
<p>学习</p>
</div>
<div>
<a href="">器材</a>
<a href="">大师</a>
<a href="">实战</a>
<a href="">大赛</a>
<a href="">其它</a>
<a href="">器材</a>
<a href="">器材</a>
<a href="">器材</a>
</div>
</div>
<div class="detail">
<div>
<span class="iconfont icon-renwujincheng"></span>
</div>
<div>
<p>资讯</p>
<p>学习</p>
</div>
<div>
<a href="">器材</a>
<a href="">大师</a>
<a href="">实战</a>
<a href="">大赛</a>
<a href="">其它</a>
<a href="">器材</a>
<a href="">器材</a>
<a href="">器材</a>
</div>
</div>
<div class="detail">
<div>
<span class="iconfont icon-gongdan"></span>
</div>
<div>
<p>资讯</p>
<p>学习</p>
</div>
<div>
<a href="">器材</a>
<a href="">大师</a>
<a href="">实战</a>
<a href="">大赛</a>
<a href="">其它</a>
<a href="">器材</a>
<a href="">器材</a>
<a href="">器材</a>
</div>
</div>
<div class="detail">
<div>
<span class="iconfont icon-DOC"></span>
</div>
<div>
<p>资讯</p>
<p>学习</p>
</div>
<div>
<a href="">器材</a>
<a href="">大师</a>
<a href="">实战</a>
<a href="">大赛</a>
<a href="">其它</a>
<a href="">器材</a>
<a href="">器材</a>
<a href="">器材</a>
</div>
</div>
</div>
<div class="lunbo">
<div>
<a href=""><img src="../static/images/4.jpg" alt="" /></a>
</div>
<div>
<a href=""><img src="../static/images/banner-right.jpg" alt="" /></a>
</div>
</div>
</div>
<!-- 新闻资讯 -->
<div class="indexTitle">
<h1>新闻资讯</h1>
</div>
<div class="indexArticle">
<!-- 新闻大图 -->
<div>
<a href=""><img src="../static/images/news.jpg" alt="" /></a>
</div>
<!-- 两个促销商品小图 -->
<div>
<div>
<a href=""><img src="../static/images/n-2.jpg" alt="" /></a>
<a href="">三星note10发布搭载挖孔前摄</a>
</div>
<div>
<a href=""><img src="../static/images/n-3.jpg" alt="" /></a>
<a href="">小米公布1亿像素手机信息</a>
</div>
</div>
<!-- 新闻链接 -->
<div>
<p>大隐于市的摄影师,薇薇安·迈尔!</p>
<div>
<span>[新闻]</span>
<a href="">佳能 EOS RP 12899元起</a>
</div>
<div>
<span>[新闻]</span>
<a href="">定焦,变焦, 新人小白如何选择?这三款值得买</a>
</div>
<div>
<span>[新闻]</span>
<a href="">新一代入门神器? 佳能EOS 850D将到来</a>
</div>
<div>
<span>[新闻]</span>
<a href="">无低通次旗舰 D7500套机6899元</a>
</div>
</div>
<div>
<div>
<span>[新闻]</span>
<a href="">佳能注册相机无线充电和眼控对焦专利</a>
</div>
<div>
<span>[新闻]</span>
<a href="">复古全幅单反 尼康Df套机14500元</a>
</div>
<div>
<span>[新闻]</span>
<a href="">索尼α7R IV超广套装售42698元</a>
</div>
<div>
<span>[新闻]</span>
<a href="">RF大三元长焦 RF70-200mm售17699</a>
</div>
<div>
<span>[新闻]</span>
<a href="">有所保留 佳能EOS-1D X III再曝新功能</a>
</div>
</div>
<!-- 促销链接 -->
<div>
<p>元旦,春节双节联动,备货啦!</p>
<div>
<span>[促销]</span>
<a href="">佳能 EOS RP 12899元起</a>
</div>
<div>
<span>[促销]</span>
<a href="">定焦,变焦, 新人小白如何选择?这三款值得买</a>
</div>
<div>
<span>[促销]</span>
<a href="">新一代入门神器? 佳能EOS 850D将到来</a>
</div>
<div>
<span>[促销]</span>
<a href="">无低通次旗舰 D7500套机6899元</a>
</div>
</div>
<div>
<div>
<span>[促销]</span>
<a href="">佳能注册相机无线充电和眼控对焦专利</a>
</div>
<div>
<span>[促销]</span>
<a href="">复古全幅单反 尼康Df套机14500元</a>
</div>
<div>
<span>[促销]</span>
<a href="">索尼α7R IV超广套装售42698元</a>
</div>
<div>
<span>[促销]</span>
<a href="">RF大三元长焦 RF70-200mm售17699</a>
</div>
<div>
<span>[促销]</span>
<a href="">有所保留 佳能EOS-1D X III再曝新功能</a>
</div>
</div>
</div>
<!-- 图片专区 -->
<div class="indexTitle">
<h1>图片专区</h1>
</div>
<div class="indexPicture">
<div class="picture">
<div>
<a href="">美女</a>
<span>纵观摄影艺术</span>
</div>
<div>
<div>
<a href=""><img src="../static/images/img1.jpg" alt="" /></a>
<a href="">阴沉夏日的柔美身姿 复古少女的藕荷色心情</a>
</div>
<div>
<a href=""><img src="../static/images/img2.jpg" alt="" /></a>
<a href="">愿你生活的都是每一天都是快快乐乐的, 一定要</a>
</div>
<div>
<a href=""><img src="../static/images/img3.jpg" alt="" /></a>
<a href="">今夜我不关心人类,我只想你,从爱上你的那天起</a>
</div>
<div>
<a href=""><img src="../static/images/img4.jpg" alt="" /></a>
<a href="">我转头,看见你走来,在阳光里,于是笑容从我心里溢出</a>
</div>
</div>
</div>
<div class="picture">
<div>
<a href="">健康</a>
<span>纵观摄影艺术</span>
</div>
<div>
<div>
<a href=""><img src="../static/images/img1.jpg" alt="" /></a>
<a href="">阴沉夏日的柔美身姿 复古少女的藕荷色心情</a>
</div>
<div>
<a href=""><img src="../static/images/img3.jpg" alt="" /></a>
<a href="">愿你生活的都是每一天都是快快乐乐的, 一定要</a>
</div>
<div>
<a href=""><img src="../static/images/img4.jpg" alt="" /></a>
<a href="">今夜我不关心人类,我只想你,从爱上你的那天起</a>
</div>
<div>
<a href=""><img src="../static/images/img5.jpg" alt="" /></a>
<a href="">我转头,看见你走来,在阳光里,于是笑容从我心里溢出</a>
</div>
</div>
</div>
<div class="picture">
<div>
<a href="">青春</a>
<span>纵观摄影艺术</span>
</div>
<div>
<div>
<a href=""><img src="../static/images/img5.jpg" alt="" /></a>
<a href="">阴沉夏日的柔美身姿 复古少女的藕荷色心情</a>
</div>
<div>
<a href=""><img src="../static/images/img3.jpg" alt="" /></a>
<a href="">愿你生活的都是每一天都是快快乐乐的, 一定要</a>
</div>
<div>
<a href=""><img src="../static/images/img2.jpg" alt="" /></a>
<a href="">今夜我不关心人类,我只想你,从爱上你的那天起</a>
</div>
<div>
<a href=""><img src="../static/images/img1.jpg" alt="" /></a>
<a href="">我转头,看见你走来,在阳光里,于是笑容从我心里溢出</a>
</div>
</div>
</div>
</div>
<!-- 二手交易 -->
<div class="indexTitle">
<h1>二手交易</h1>
</div>
<div class="indexShop">
<div>
<a href="">抢好货</a>
<span>0低价, 便捷,安全,快速</span>
</div>
<div>
<span>热门分类</span>
<a href="">美女写真</a>
<a href="">日本美女</a>
<a href="">美国美女</a>
<a href="">国内美女</a>
<a href="">AV美女</a>
</div>
<div>
<div class="commList">
<div>
<div>
<a href=""
><img src="../static/images/shop/shop1.jpg" alt=""
/></a>
</div>
<a href="">美女写真墙上装饰贴画快感艺术海报</a>
<div>
<span>¥345</span>
<span>美女</span>
</div>
</div>
<div>
<div>
<a href=""
><img src="../static/images/shop/shop2.jpg" alt=""
/></a>
</div>
<a href="">美女写真墙上装饰贴画快感艺术海报</a>
<div>
<span>¥345</span>
<span>素颜</span>
</div>
</div>
<div>
<div>
<a href=""
><img src="../static/images/shop/shop3.jpg" alt=""
/></a>
</div>
<a href="">美女写真墙上装饰贴画快感艺术海报</a>
<div>
<span>¥345</span>
<span>大学生</span>
</div>
</div>
<div>
<div>
<a href=""
><img src="../static/images/shop/shop4.jpg" alt=""
/></a>
</div>
<a href="">美女写真墙上装饰贴画快感艺术海报</a>
<div>
<span>¥345</span>
<span>美女</span>
</div>
</div>
<div>
<div>
<a href=""
><img src="../static/images/shop/shop5.jpg" alt=""
/></a>
</div>
<a href="">美女写真墙上装饰贴画快感艺术海报</a>
<div>
<span>¥345</span>
<span>美女</span>
</div>
</div>
<div>
<div>
<a href=""
><img src="../static/images/shop/shop6.jpg" alt=""
/></a>
</div>
<a href="">美女写真墙上装饰贴画快感艺术海报</a>
<div>
<span>¥345</span>
<span>美女</span>
</div>
</div>
<div>
<div>
<a href=""
><img src="../static/images/shop/shop7.jpg" alt=""
/></a>
</div>
<a href="">美女写真墙上装饰贴画快感艺术海报</a>
<div>
<span>¥345</span>
<span>美女</span>
</div>
</div>
<div>
<div>
<a href=""
><img src="../static/images/shop/shop8.jpg" alt=""
/></a>
</div>
<a href="">美女写真墙上装饰贴画快感艺术海报</a>
<div>
<span>¥345</span>
<span>美女</span>
</div>
</div>
</div>
<div class="commClass">
<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>
<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 class="indexTitle">
<h1>合作单位</h1>
</div>
<div class="work_link">
<div>
<a href="">html合作单位</a>
</div>
<div>
<a href="">python合作单位</a>
</div>
<div>
<a href="">css合作单位</a>
</div>
<div>
<a href="">php合作单位</a>
</div>
<div>
<a href="">javascript合作单位</a>
</div>
<div>
<a href="">javascript合作单位</a>
</div>
<div>
<a href="">javascript合作单位</a>
</div>
<div>
<a href="">javascript合作单位</a>
</div>
<div>
<a href="">javascript合作单位</a>
</div>
<div>
<a href="">javascript合作单位</a>
</div>
<div>
<a href="">javascript合作单位</a>
</div>
<div>
<a href="">javascript合作单位</a>
</div>
</div>
<!-- 全站页脚 -->
<div class="public_footer">
<div class="footer_nav">
<a href="">首页</a>
<a href="">联系我们</a>
<a href="">招聘信息</a>
<a href="">友情链接</a>
<a href="">用户服务协议</a>
<a href="">隐私权声明</a>
<a href="">法律投诉声明</a>
</div>
<div class="footer_logo">
<img src="../static/images/logo.png" alt="" />
</div>
<div class="footer_info">
<p>
2019 fengniao.com. All rights
reserved.安徽闹着玩有限公司(无聊网)版权所有
</p>
<p>皖ICP证150110号 京ICP备14323013号-2 皖公网安备110108024357788号</p>
<p>
违法和不良信息举报电话:
<a href="tel:0551-1234567">0551-1234567</a> 举报邮箱:
<a href="mailto:admin@baidu.com">admin@baidu.com</a>
</p>
</div>
<div class="footer_ewm">
<p>关注公众号</p>
<img src="../static/images/erwei-code.png" alt="" />
</div>
</div>
</body>
</html>
/* 引入全站公共清除样式 */
@import "../static/css/reset.css";
/* 引入全站头部导航 */
@import "../components/public/publicHander/publicHander.css";
/* 引入全站首页导航、搜索框、轮播图、快速进入按钮 */
@import "../components/index/indexHeader/indexHeader.css";
/* 引入首页大标题样式 */
@import "../components/index/indexTitle/indexTitle.css";
/* 引入首页新闻资讯模块样式 */
@import "../components/article/index_article.css";
/* 引入首页图片库模块样式 */
@import "../components/picture/index_picture.css";
/* 引入首页二手交易模块样式 */
@import "../components/shop/index_shop.css";
/* 引入首页合作单位模块样式 */
@import "../components/index/indexLink/indexLink.css";
/* 引入全站尾部导航 */
@import "../components/public/publicFooter/publicFooter.css";
/* 引入全站公共清除样式 reset.css*/
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-size: 15px;
}
a {
text-decoration: none;
color: #555;
}
a:hover {
color: red;
}
li {
list-style-type: none;
}
/* 全站头部导航 publicHander.css*/
/* 导入样式重置文件 */
@import "../public_reset.css";
/* 全站页眉样式 */
.public_header {
/* 导航定义为弹性布局 */
display: flex;
flex-flow: row nowrap;
align-items: center;
/* 基本样式 */
background-color: lightgreen;
height: 45px;
padding: 0px 20px;
}
/* 基本导航左对齐 */
.public_header a {
color: black;
padding: 13px 15px;
}
.public_header a:hover {
color: white;
background-color: blanchedalmond;
}
/* 登录和注册右对齐 */
.public_header > span {
margin-left: auto;
}
.public_header > span > a:hover {
background-color: lightgreen;
}
/* 定义登录字体图标样式 */
.public_header > span > a > label {
font-size: 18px;
padding: 0px 15px;
}
/* 全站页脚 publicFooter.css*/
@import "../public_reset.css";
/* 公共页脚样式,按网格显示 */
.public_footer {
/* 基本样式 */
height: 260px;
background-color: lightgreen;
/* 页脚样式定义为网格布局 */
display: grid;
grid-template-columns: 150px 580px 400px; /*定义一个3列2行的网格*/
grid-template-rows: 70px 140px;
/* 通过网格区域名称来填充网格 */
grid-template-areas:
"footer_nav footer_nav footer_ewm"
"footer_logo footer_info footer_ewm";
/* 风格内容横向和纵向都居中对齐 */
align-content: center;
justify-content: center;
}
/* 页脚导航样式 */
.footer_nav {
grid-area: footer_nav; /*设置导航内容的区域化名称*/
}
.footer_nav > a {
padding: 0px 15px;
color: black;
}
.footer_nav > a:hover {
color: white;
}
/* 网站logo样式 */
.footer_logo {
width: 160px;
height: 76px;
grid-area: footer_logo; /*设置logo区域化名称*/
}
/* 网站logo的图片大小自适应 */
.footer_logo > img {
max-width: 100%;
max-height: 100%;
}
/* 网站备案内容样式 */
.footer_info {
grid-area: footer_info; /*设置网站备案内容区域化名称*/
line-height: 40px;
padding-left: 20px;
}
/* 二维码样式 */
.footer_ewm {
grid-area: footer_ewm; /*设置二维码区域化名称*/
padding-left: 30px;
border-left: 2px solid black;
/* 设置二维码图标为弹性布局,主轴方向为列,不换行 */
display: flex;
flex-flow: column nowrap;
}
.footer_ewm > p {
text-align: center;
width: 100px;
}
/* 设置二维码图片的宽度和高度 */
.footer_ewm > img {
width: 110px;
height: 110px;
margin-top: 10px;
}
/* 首页导航,轮播图 搜索框 indexHeader.css*/
@import "../../public/public_reset.css";
.index_header {
background-color: white;
display: flex;
flex-flow: column nowrap;
padding: 30px 30px;
}
/* 全站首页logo\搜索框\快速定位按钮 */
.index_header > .logo_search {
display: flex;
/* flex-flow: row nowrap; */
align-items: center;
}
.index_header > .logo_search > div:nth-of-type(2) {
/* 搜索框右对齐 */
margin-left: auto;
padding: 0px 30px;
display: flex;
/* flex-flow: row nowrap; */
align-items: center;
width: 300px;
}
/* 搜索框输入框 */
.index_header > .logo_search input {
width: 300px;
align-self: end;
height: 40px;
border: 2px solid #ccc;
border-radius: 10px;
}
/* 放大镜图标 */
.index_header > .logo_search label {
font-size: 2rem;
}
/* 字体图标 点赞 评论 下载 会员等 */
.index_header > .logo_search span {
font-size: 2rem;
padding: 0px 5px;
}
.index_header > .logo_search span:hover {
color: red;
}
/* 全站首页导航 */
.index_header > .nav {
margin: 20px 0px;
/* 整体布局为弹性布局 */
display: flex;
/* flex-flow: row nowrap; */
justify-content: space-between;
align-items: center;
}
/* 首页导航中每一个小的导航块 */
.index_header > .nav > .detail {
width: 300px;
height: 50px;
display: flex;
/* flex-flow: row nowrap; */
justify-content: space-evenly;
align-items: center;
}
/* 导航块前面的字体图标 */
.index_header > .nav > .detail > div:first-of-type > span {
font-size: 3rem;
color: red;
}
/* 字体图标后的分类导航提示 */
.index_header > .nav > .detail > div:nth-of-type(2) > p {
color: #555;
}
/* 分类导航中的每一个小的导航链接 */
.index_header > .nav > .detail > div:last-of-type {
width: 170px;
display: flex;
border-left: 2px solid #ccc;
/* 弹性布局主轴方向为横向换行,上面规定了宽度 */
flex-flow: row wrap;
justify-content: space-evenly;
align-items: center;
}
.index_header > .nav > .detail > div:last-of-type > a {
padding: 0px 5px;
}
/* 全站首页轮播图 */
.index_header > .lunbo {
margin-top: 10px;
display: flex;
/* flex-flow: row nowrap; */
justify-content: space-evenly;
align-items: center;
}
.index_header > .lunbo > div {
height: 338px;
}
.index_header > .lunbo > div img {
width: 100%;
height: 100%;
}
/* 首页合作合作单位模块样式 indexLink.css*/
@import "../../public/public_reset.css";
/* 合作单位样式 */
.work_link {
/* 基本样式 */
margin-top: 20px;
background-color: white;
max-height: 130px;
padding: 15px 30px;
/* 整体采用网格布局,单元格自动填充 */
display: grid;
grid-template-columns: repeat(auto-fill, 150px);
grid-template-rows: repeat(auto-fill, 40px);
justify-content: space-evenly;
align-content: space-evenly;
}
/* 每个合作单位的链接被包在一个div中 */
.work_link > div {
font-size: 1.5rem;
/* 设置为弹性布局,为了设置其中链接的对齐方式 */
display: flex;
justify-content: center;
align-items: center;
}
.work_link > div a {
color: grey;
}
.work_link > div a:hover {
color: red;
}
/* 首页大标题样式 indexTitle.css*/
/* 首页大标题样式 */
.indexTitle {
width: 140px;
height: 45px;
/* 大标题下方有一条红色的下划线 */
border-bottom: 4px solid red;
margin-top: 20px;
/* 居中显示 */
margin-left: auto;
margin-right: auto;
}
.indexTitle > h1 {
font-size: xx-large;
text-align: center;
color: #555;
letter-spacing: 3px;
}
/* 首页新闻资讯模块样式 index_article.css*/
@import "../../static/css/reset.css";
@import "../public/public_reset.css";
.indexArticle {
/* 基本样式 */
margin: 20px auto;
width: 1255px;
height: 445px;
background-color: white;
border-radius: 10px;
/* 新闻资讯中的内容按栅格化布局 */
display: grid;
/* 定义一个2行3列的表格 */
grid-template-columns: 421px 350px 350px;
grid-template-rows: 210px 210px;
/* 栅格的填充方式为列优先填充 */
grid-auto-flow: column;
justify-content: space-evenly;
align-content: center;
}
.indexArticle:hover {
/* 给整个新闻资讯模块添加一个鼠标悬浮效果 */
box-shadow: 0px 0px 10px #555;
}
.indexArticle a {
font-size: 0.9rem;
color: #555;
}
.indexArticle a:hover {
color: red;
}
/* 新闻资讯中大图的对齐方式为居中对齐 */
.indexArticle > div:first-of-type {
/* justify-self: center;
align-self: center; */
/* 设置该项目在网格中为居中对齐 */
place-self: center;
}
/* 新闻资讯中两个小图的布局 */
.indexArticle > div:nth-of-type(2) {
/* 两个小图布局为弹性布局 */
display: flex;
flex-flow: row nowrap;
}
.indexArticle > div:nth-of-type(2) > div {
width: 200px;
height: 135px;
}
/* 两个小图的大小充满整个div */
.indexArticle > div:nth-of-type(2) > div img {
width: 100%;
height: 100%;
}
/* 新闻资讯中新闻和促销的链接样式 */
.indexArticle > div:nth-last-of-type(-n + 4) {
align-self: center;
}
.indexArticle > div:nth-last-of-type(-n + 4) div {
padding: 5px 10px;
}
.indexArticle > div:nth-last-of-type(-n + 4) p {
font-size: 1.5rem;
color: red;
}
.indexArticle > div:nth-last-of-type(-n + 4) span {
color: gray;
}
/* 首页图片专区模块样式 index_picture.css*/
@import "../../static/css/reset.css";
@import "../public/public_reset.css";
/* 整个图片模块的样式 */
.indexPicture {
width: 1255px;
margin: 20px auto;
/* 整体设置为弹性布局,横向不换行 */
display: flex;
flex-flow: row nowrap;
justify-content: space-evenly;
}
/* 图片模块中3个小模块的样式 */
.indexPicture > .picture {
/* 基本样式 */
width: 410px;
height: 495px;
margin: 20px;
background-color: white;
border-radius: 10px;
/* 每一个小模块中的布局方式为弹性布局,列为主轴 */
display: flex;
flex-flow: column nowrap;
align-items: center;
}
/*3个图片小模块的鼠标悬浮样式 */
.indexPicture > .picture:hover {
box-shadow: 0px 0px 10px #555;
}
/* 每个图片小模块的头部标题样式 */
.indexPicture > .picture > div:first-of-type {
height: 70px;
width: 380px;
padding: 20px;
border-bottom: 2px solid #ccc;
}
/* 图片模块头部大标题的样式 */
.indexPicture > .picture > div:first-of-type > a {
font-size: 1.7rem;
color: #555;
}
.indexPicture > .picture > div:first-of-type > a:hover {
color: red;
}
/* 图片模块头部大标题详情样式 */
.indexPicture > .picture > div:first-of-type > span {
padding-left: 30px;
color: red;
}
/* 4个小图+链接的样式 */
.indexPicture > .picture > div:last-of-type {
margin-top: 20px;
/* 设置为2行2列的网格布局 */
display: grid;
grid-template-rows: repeat(2, 185px);
grid-template-columns: repeat(2, 195px);
/* 填充方式为按行的方向填充 */
grid-auto-flow: row;
place-content: space-evenly;
place-items: center;
}
.indexPicture > .picture > div:last-of-type > div {
margin: 10px;
}
.indexPicture > .picture > div:last-of-type > div > a > img {
/* 图片大小固定 */
width: 100%;
height: 100%;
}
/* 首页二手交易模块样式 index_shop.css*/
@import "../public/public_reset.css";
@import "../../static/css/reset.css";
/* 设置所有的span标签为红色字体 */
span {
color: red;
}
/* 二手交易模块样式 */
.indexShop {
/* 基本样式 */
width: 1255px;
height: 595px;
margin: 20px auto;
padding: 10px;
background-color: white;
border-radius: 10px;
/* 弹性布局,列为主轴 */
display: flex;
flex-flow: column nowrap;
}
/* 二手交易模块的鼠标悬浮效果 */
.indexShop:hover {
box-shadow: 0px 0px 10px #555;
}
.indexShop > div {
margin: 10px 0px;
}
/* 二手交易模块内大标题样式 */
.indexShop > div:first-of-type > a {
font-size: 1.8rem;
margin-right: 20px;
}
/* 二手交易分类导航样式 */
.indexShop > div:nth-of-type(2) {
border-top: 1px solid #ccc;
}
.indexShop > div:nth-of-type(2) > span {
font-size: 1.6rem;
}
.indexShop > div:nth-of-type(2) > a {
margin: 0px 10px;
}
/* 二手交易模块中物品列表和分类图片样式 */
.indexShop > div:last-of-type {
/* 弹性布局,行为主轴 */
display: flex;
flex-flow: row nowrap;
height: 450px;
}
/* 二手交易物品列表样式 */
.indexShop > div > .commList {
width: 805px;
/* 交易物品整体样式为弹性布局为弹布局,横向换行 */
display: flex;
flex-flow: row wrap;
}
/* 二手交易每个物品的样式 */
.indexShop > div > .commList > div {
/* 基本样式 */
width: 186px;
height: 200px;
margin: 5px;
/* 弹性布局,竖排不换行 */
display: flex;
flex-flow: column nowrap;
justify-content: center;
}
/* 物品的图片和链接样式 */
.indexShop > div > .commList > div > div:first-of-type {
width: 186px;
height: 130px;
border: 1px solid #ccc;
border-radius: 5px;
}
/* 物品的价格和分类样式 */
.indexShop > div > .commList > div > div:last-of-type {
display: flex;
flex-flow: row nowrap;
justify-content: space-between;
}
/* 物品的分类样式 */
.indexShop > div > .commList > div > div:last-of-type > span:last-of-type {
background-color: #55ce9f;
padding: 2px 3px;
border-radius: 3px;
color: white;
}
/* 物品的图片大小固定 */
.indexShop > div > .commList img {
width: 100%;
height: 100%;
}
/* 二手交易右边分类图片样式 */
.indexShop > div > .commClass {
width: 450px;
margin: auto;
display: flex;
flex-flow: row wrap;
}
.indexShop > div > .commClass > a > img {
margin: 5px;
}
2.栅格布局12列
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>栅格12列布局</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<div class="container">
<div class="row">
<div class="header col-12">header</div>
</div>
<div class="row">
<div class="aside-left col-2">aside-left</div>
<div class="main col-8">main</div>
<div class="aside-right col-2">aside-right</div>
</div>
<div class="row">
<div class="footer col-12">footer</div>
</div>
</div>
</body>
</html>
* {
padding: 0px;
margin: 0px;
box-sizing: border-box;
}
body {
display: flex;
justify-content: center;
align-items: center;
max-width: 100vw;
min-height: 100vh;
}
.container {
min-width: 920px;
display: grid;
gap: 5px;
}
.container > .row {
display: grid;
grid-template-columns: repeat(12, 1fr);
gap: 5px;
}
.container > .row > .aside-left {
background-color: hotpink;
}
.container > .row > .aside-right {
background-color: indigo;
}
.container > .row > .main {
background-color: lawngreen;
}
.container > .row:first-of-type,
.row:last-of-type {
min-height: 53px;
}
.container > .row:nth-of-type(2) {
min-height: 500px;
}
.container > .row > .header {
background-color: blue;
}
.container > .row > .footer {
background-color: green;
}
.col-1 {
grid-column-end: span 1;
}
.col-2 {
grid-column-end: span 2;
}
.col-3 {
grid-column-end: span 3;
}
.col-4 {
grid-column-end: span 4;
}
.col-5 {
grid-column-end: span 5;
}
.col-6 {
grid-column-end: span 6;
}
.col-7 {
grid-column-end: span 7;
}
.col-8 {
grid-column-end: span 8;
}
.col-9 {
grid-column-end: span 9;
}
.col-10 {
grid-column-end: span 10;
}
.col-11 {
grid-column-end: span 11;
}
.col-12 {
grid-column-end: span 12;
}
3.电子相册
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="static/css/style.css" />
<title>电子相册</title>
</head>
<body>
<h1>我的明星相册</h1>
<div class="container">
<div class="item">
<a href=""><img src="static/images/photo.jpg" alt="" /></a>
<a href="">明星相册</a>
</div>
<div class="item">
<a href=""><img src="static/images/photo.jpg" alt="" /></a>
<a href="">明星相册</a>
</div>
<div class="item">
<a href=""><img src="static/images/photo.jpg" alt="" /></a>
<a href="">明星相册</a>
</div>
<div class="item">
<a href=""><img src="static/images/photo.jpg" alt="" /></a>
<a href="">明星相册</a>
</div>
<div class="item">
<a href=""><img src="static/images/photo.jpg" alt="" /></a>
<a href="">明星相册</a>
</div>
<div class="item">
<a href=""><img src="static/images/photo.jpg" alt="" /></a>
<a href="">明星相册</a>
</div>
<div class="item">
<a href=""><img src="static/images/photo.jpg" alt="" /></a>
<a href="">明星相册</a>
</div>
<div class="item">
<a href=""><img src="static/images/photo.jpg" alt="" /></a>
<a href="">明星相册</a>
</div>
<div class="item">
<a href=""><img src="static/images/photo.jpg" alt="" /></a>
<a href="">明星相册</a>
</div>
<div class="item">
<a href=""><img src="static/images/photo.jpg" alt="" /></a>
<a href="">明星相册</a>
</div>
<div class="item">
<a href=""><img src="static/images/photo.jpg" alt="" /></a>
<a href="">明星相册</a>
</div>
<div class="item">
<a href=""><img src="static/images/photo.jpg" alt="" /></a>
<a href="">明星相册</a>
</div>
</div>
</body>
</html>
* {
padding: 0px;
margin: 0px;
box-sizing: border-box;
}
a {
text-decoration: none;
color: white;
}
a:hover {
color: coral;
}
h1 {
color: white;
text-align: center;
letter-spacing: 5px;
font-size: 2.5rem;
font-weight: 400;
text-shadow: 2px 2px 2px #555;
margin-top: 20px;
}
body {
display: flex;
flex-flow: column nowrap;
justify-content: center;
align-items: center;
background-color: lightseagreen;
}
.container {
min-width: 100vw;
min-height: 100vh;
padding: 50px;
display: grid;
grid-template-columns: repeat(auto-fill, 250px);
grid-template-rows: repeat(auto-fill, 280px);
justify-content: space-evenly;
align-content: space-evenly;
gap: 10px;
}
.container img {
width: 100%;
}
.container > .item {
padding: 30px;
background-color: lightskyblue;
display: flex;
flex-flow: column nowrap;
justify-content: center;
align-items: center;
border-radius: 10px;
}
.container > .item > a:first-of-type:hover {
box-shadow: 0 0 10px #555;
width: calc(100% * 1.02);
background-color: lightslategray;
}