使用flex布局,模仿m.php.cn首页(补12.27)
效果图
目录结构
布局分析
首先将页面分割为三部分,header
、main
、footer
,其中header
、和footer
是固定的,而main
则是自适应高度。
HTML代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>移动端页面布局</title>
<link rel="stylesheet" href="css/index.css">
</head>
<body>
<!--页面头部-->
<div class="page-header">
<a href=""><img src="image/login.png" alt=""></a>
<a href=""><img src="image/logo.png" alt=""></a>
<a href=""><i class="iconfont"></i></a>
</div>
<div class="page-main">
<!--头部banner滚动图-->
<div class="banner">
<a href=""><img src="image/banner/banner1.jpg" alt=""></a>
</div>
<!--页面头部导航-->
<div class="nav">
<a class="nav-list" href="">
<img src="image/navs/html.png" alt="">
<span>HTML/css</span>
</a>
<a class="nav-list" href="">
<img src="image/navs/JavaScript.png" alt="">
<span>JavaScript</span>
</a>
<a class="nav-list" href="">
<img src="image/navs/code.png" alt="">
<span>服务端</span>
</a>
<a class="nav-list" href="">
<img src="image/navs/sql.png" alt="">
<span>数据库</span>
</a>
<a class="nav-list" href="">
<img src="image/navs/app.png" alt="">
<span>移动端</span>
</a>
<a class="nav-list" href="">
<img src="image/navs/manual.png" alt="">
<span>手册</span>
</a>
<a class="nav-list" href="">
<img src="image/navs/tool2.png" alt="">
<span>工具</span>
</a>
<a class="nav-list" href="">
<img src="image/navs/live.png" alt="">
<span>直播</span>
</a>
</div>
<!--推荐课程-->
<div class="recommend">
<h3>推荐课程</h3>
<div class="rec-top">
<a href=""><img src="image/1.jpg" alt=""></a>
<a href=""><img src="image/2.jpg" alt=""></a>
</div>
<div class="rec-list">
<a href=""><img src="image/3.jpg" alt=""></a>
<div class="rec-content">
<h2><a href="">CI框架30分钟极速入门</a></h2>
<p>
<span class="level">中级</span>
<span>55724次播放</span>
</p>
</div>
</div>
<div class="rec-list">
<a href=""><img src="image/4.jpg" alt=""></a>
<div class="rec-content">
<h2><a href="">2018前端入门_HTML5</a></h2>
<p>
<span class="level">初级</span>
<span>257725次播放</span>
</p>
</div>
</div>
</div>
<!--最新更新-->
<div class="update">
<h3>最新更新</h3>
<div class="update-list">
<a href=""><img src="image/2-1.jpg" alt=""></a>
<div class="update-content">
<h2><a href="">2019python自学视频</a></h2>
<span>本课程适合想从零开始学习 Python 编程语言的开发</span>
<div class="update-level">
<span class="level">中级</span>
<span>55724次播放</span>
</div>
</div>
</div>
<div class="update-list">
<a href=""><img src="image/2-2.png" alt=""></a>
<div class="update-content">
<h2><a href="">2019python自学视频</a></h2>
<span>本课程适合想从零开始学习 Python 编程语言的开发人员。由浅入深的带你进入python</span>
<div class="update-level">
<span class="level">中级</span>
<span>55724次播放</span>
</div>
</div>
</div>
<div class="update-list">
<a href=""><img src="image/2-3.jpg" alt=""></a>
<div class="update-content">
<h2><a href="">2019python自学视频</a></h2>
<span>本课程适合想从零开始学习 Python 编程语言的开发人员。由浅入深的带你进入python</span>
<div class="update-level">
<span class="level">中级</span>
<span>55724次播放</span>
</div>
</div>
</div>
<div class="update-list">
<a href=""><img src="image/2-4.png" alt=""></a>
<div class="update-content">
<h2><a href="">2019python自学视频</a></h2>
<span>本课程适合想从零开始学习 Python 编程语言的开发人员。由浅入深的带你进入python</span>
<div class="update-level">
<span class="level">中级</span>
<span>55724次播放</span>
</div>
</div>
</div>
<div class="update-list">
<a href=""><img src="image/2-5.jpg" alt=""></a>
<div class="update-content">
<h2><a href="">2019python自学视频</a></h2>
<span>本课程适合想从零开始学习 Python 编程语言的开发人员。由浅入深的带你进入python</span>
<div class="update-level">
<span class="level">中级</span>
<span>55724次播放</span>
</div>
</div>
</div>
<div class="update-list">
<a href=""><img src="image/2-6.png" alt=""></a>
<div class="update-content">
<h2><a href="">2019python自学视频</a></h2>
<span>本课程适合想从零开始学习 Python 编程语言的开发人员。由浅入深的带你进入python</span>
<div class="update-level">
<span class="level">中级</span>
<span>55724次播放</span>
</div>
</div>
</div>
</div>
<!--最新文章-->
<div class="docs">
<h3>最新文章</h3>
<div class="doc-list">
<div class="doc-content">
<a href=""><h2>VSCode,控制台乱码设置</h2></a>
<a href="">发布时间:2019-12-30</a>
</div>
<a href="image/doc/vscode.jpg"><img src="image/doc/vscode.jpg" alt=""></a>
</div>
<div class="doc-list">
<div class="doc-content">
<a href=""><h2>VSCode,控制台乱码设置</h2></a>
<a href="">发布时间2019-12-30</a>
</div>
<a href=""><img src="image/doc/facebookcrsf.jpg" alt=""></a>
</div>
<div class="doc-list">
<div class="doc-content">
<a href=""><h2>VSCode,控制台乱码设置</h2></a>
<a href="">发布时间2019-12-30</a>
</div>
<a href=""><img src="image/doc/yii.jpg" alt=""></a>
</div>
<div class="doc-list">
<div class="doc-content">
<a href=""><h2>VSCode,控制台乱码设置</h2></a>
<a href="">发布时间2019-12-30</a>
</div>
<a href=""><img src="image/doc/facebookxss.jpg" alt=""></a>
</div>
<div class="doc-list">
<div class="doc-content">
<a href=""><h2>VSCode,控制台乱码设置</h2></a>
<a href="">发布时间2019-12-30</a>
</div>
<a href=""><img src="image/doc/yii.jpg" alt=""></a>
</div>
<a class="a-more" href="">更多内容</a>
</div>
<!--最新博文-->
<div class="blog-articles">
<h3>最新博文</h3>
<div class="com-articles">
<a href=""><h2>composer安装laravel,Nginx服务器路配置解决404问题,创建简单的控制</h2></a>
<a href="">2019-12-27</a>
</div>
<div class="com-articles">
<a href=""><h2>composer安装laravel,Nginx服务器路配置解决404问题,创建简单的控制</h2></a>
<a href="">2019-12-27</a>
</div>
<div class="com-articles">
<a href=""><h2>composer安装laravel,Nginx服务器路配置解决404问题,创建简单的控制</h2></a>
<a href="">2019-12-27</a>
</div>
<div class="com-articles">
<a href=""><h2>composer安装laravel,Nginx服务器路配置解决404问题,创建简单的控制</h2></a>
<a href="">2019-12-27</a>
</div>
<a class="a-more" href="">更多内容</a>
</div>
<!--最新问答-->
<div class="questions">
<h3>最新问答</h3>
<div class="com-articles">
<span>composer安装laravel,Nginx服务器路配置解决404问题,创建简单的控制</span>
<span>2019-12-27</span>
</div>
<div class="com-articles">
<a href=""><h2>composer安装laravel,Nginx服务器路配置解决404问题,创建简单的控制</h2></a>
<a href="">2019-12-27</a>
</div>
<div class="com-articles">
<a href=""><h2>composer安装laravel,Nginx服务器路配置解决404问题,创建简单的控制</h2></a>
<a href="">2019-12-27</a>
</div>
<div class="com-articles">
<a href=""><h2>composer安装laravel,Nginx服务器路配置解决404问题,创建简单的控制</h2></a>
<a href="">2019-12-27</a>
</div>
<div class="com-articles">
<a href=""><h2>composer安装laravel,Nginx服务器路配置解决404问题,创建简单的控制</h2></a>
<a href="">2019-12-27</a>
</div>
<a class="a-more" href="">更多内容</a>
</div>
</div>
<!--页面底部导航-->
<div class="page-footer">
<a href=""><i class="iconfont"></i>首页</a>
<a href=""><i class="iconfont"></i>视频</a>
<a href=""><i class="iconfont"></i>社区</a>
<a href=""><i class="iconfont"></i>我的</a>
</div>
</body>
</html>
CSS代码
/*引入字体图标库*/
@font-face {
font-family: 'iconfont';
src: url('../../html/1220/css/font/iconfont.eot');
src: url('../../html/1220/css/font/iconfont.eot?#iefix') format('embedded-opentype'),
url('../../html/1220/css/font/iconfont.woff2') format('woff2'),
url('../../html/1220/css/font/iconfont.woff') format('woff'),
url('../../html/1220/css/font/iconfont.ttf') format('truetype'),
url('../../html/1220/css/font/iconfont.svg#iconfont') format('svg');
}
.iconfont {
font-family: "iconfont", serif !important;
font-size: 16px;
font-style: normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
/*初始化 --公共样式*/
*{
margin: 0;
padding: 0;
/* outline: 1px dashed red;*/
}
a{
color: #888888;
text-decoration: none;
}
a:hover{
cursor: pointer;
}
h2{
font-weight: normal;
}
h3{
font-size: 18px;
}
/*页面整体样式*/
body{
width: 100vw;
height: 100vh;
max-width: 768px;
font-size: 13px;
color: #888888;
background-color: #edeff0;
box-sizing: border-box;
display: flex;
flex-flow: column nowrap;
margin: 0 auto;
}
/*#8e888e -图标原色/图标红色#ff0000 /级别背景色 #595757*/
/*页头页尾与主体内容布局样式*/
body >.page-header,body >.page-main,body >.page-footer{
width: 100%;
max-width: 768px;
min-width: 320px;
}
/*页面头部 header*/
body >.page-header{
height: 42px;
background-color: #2d353c;
display: flex;
justify-content:space-between;
}
body >.page-header > a:first-of-type >img {
width: 25px;
height: 25px;
border: 1px solid #8F9498;
border-radius: 50px;
margin: 8px 8px;
}
body >.page-header > a:nth-child(2) >img{
height: 42px;
}
body >.page-header > a:last-of-type{
line-height: 42px;
text-align: right;
margin-right: 14px;
}
body >.page-header >a>i{
font-size: 20px;
color: #fff;
}
/*页面主体内容 main*/
body >.page-main{
width: 100%;
flex: auto;
overflow: auto;
display: flex;
flex-flow: column nowrap;
}
/*banner图 样式*/
body >.page-main >.banner{
height: 150px;
}
.banner >a{
width: 100%;
height: 150Px;
display: inline-block;
}
.banner >a >img{
width: 100%;
height: 150Px;
}
/*顶部导航区 样式*/
body >.page-main >.nav{
background-color: #fff;
margin-top: 10px;
display: flex;
flex-flow: row wrap;
justify-content: space-between;
}
.nav-list{
width: 160px;
height: 75px;
display: flex;
flex-flow: column nowrap;
justify-content: center;
align-items: center;
margin-top: 10px;
}
.nav-list> img{
width: 45px;
height: 45px;
}
.nav-list> span{
font-weight: bolder;
}
/*推荐课程*/
body>.page-main>.recommend{
height: 400px;
margin: 20px 10px 0 10px;
display: flex;
flex-flow: column nowrap;
}
.recommend>.rec-top{
margin: 10px 0;
display: flex;
flex-flow: row nowrap;
justify-content: space-between;
}
.recommend>.rec-top> a{
width: 367px;
height: 90px;
line-height: 90px;
}
.recommend>.rec-top> a> img{
width: 367px;
height: 90px;
}
.recommend >.rec-list{
height: 100px;
margin: 10px 0;
padding: 10px 10px;
background-color: #fff;
display: flex;
flex-flow: row nowrap;
}
.recommend >.rec-list >a,.recommend >.rec-list>.rec-content{
width: 295px;
height: 80px;
margin: auto;
}
.recommend >.rec-list >a>img{
width: 295px;
height: 80px;
}
.recommend >.rec-list>.rec-content{
margin-left: 10px;
flex: auto;
}
.recommend >.rec-list>.rec-content >p{
height: 20px;
line-height: 20px;
margin-top: 10px;
}
.recommend >.rec-list>.rec-content >p >span:first-of-type{
width: 40px;
height: 20px;
line-height: 20px;
background-color:#595757;
font-size: 12px;
color: #fff;
text-align: center;
border-radius: 5px;
margin-right: 5px;
display: inline-block;
}
/*最新更新*/
body>.page-main>.update{
display: flex;
flex-flow: column nowrap;
margin: 20px 10px 0 10px;
}
.update>.update-list{
background-color: #fff;
margin-top: 10px;
padding: 10px 10px;
display: flex;
flex-flow: row nowrap;
}
.update>.update-list>a{
width: 295px;
height: 80px;
}
.update>.update-list>a >img{
width: 295px;
height: 80px;
}
.update>.update-list>.update-content{
height: 80px;
margin-left: 10px;
flex: auto;
display: flex;
flex-flow: column nowrap;
justify-content: space-between;
}
.update>.update-list>.update-content>.update-level{
display: flex;
flex-flow: row nowrap;
justify-content: space-between;
}
.update>.update-list>.update-content>.update-level>.level{
width: 40px;
height: 20px;
line-height: 20px;
background-color:#595757;
font-size: 12px;
color: #fff;
text-align: center;
border-radius: 5px;
margin-right: 5px;
display: inline-block;
}
/*最新文章*/
body>.page-main>.docs{
display: flex;
flex-flow: column nowrap;
margin: 20px 10px 0 10px;
}
.docs>.doc-list{
height: 65px;
background-color: #fff;
margin: 10px 0;
padding: 10px 10px;
display: flex;
flex-flow: row nowrap;
}
.docs>.doc-list>a{
width: 218px;
height: 65px;
}
.docs>.doc-list>a>img{
width: 218px;
height: 65px;
}
.docs>.doc-list>.doc-content{
flex: auto;
display: flex;
flex-flow: column nowrap;
}
.docs>.doc-list>.doc-content>a:last-of-type{
margin-top: 10px;
}
.docs>.doc-list>.doc-content>a>h2,.com-articles>a>h2{
font-size: 14px;
font-weight: bold;
white-space: nowrap;
}
/*最新博文*/
body>.page-main>.blog-articles{
margin: 20px 10px 0 10px;
display: flex;
flex-flow: column nowrap;
}
.com-articles{
height: 30px;
line-height: 30px;
background-color: #fff;
margin: 10px 0;
padding: 10px 10px;
display: flex;
flex-flow: row nowrap;
justify-content: space-between;
}
.a-more{
height: 30px;
background-color: #fff;
line-height: 30px;
text-align: center;
}
/*最新问答*/
body>.page-main>.questions{
margin: 20px 10px 0 10px;
display: flex;
flex-flow: column nowrap;
}
/*页面尾部导航 footer*/
body >.page-footer{
height: 60px;
background-color: #eeeeee;
display: flex;
justify-content:space-around ;
}
body>.page-footer>a{
height: 60px;
font-size: 1.1rem;
line-height: 60px;
text-align: center;
}
body>.page-footer>a:nth-child(1){
color: #ff2017;
}
body>.page-footer>a:nth-child(1)>i{
color: #ff2017;
}
body>.page-footer>a>i{
font-size: 24px;
}