html代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<!--引入阿里字体图标库的css-->
<link rel="stylesheet" href="../iconfont/iconfont.css">
<link rel="stylesheet" href="mobile.css">
<title>移动端布局</title>
</head>
<body>
<!-- 页眉,使用字体图标代替右上角图片 -->
<header>
<img src="img/user.jpg" alt="">
<img src="img/logo.png" alt="">
<i class="iconfont icon-icon_shezhi"></i>
</header>
<!-- 主体,有三部分内容 -->
<main>
<!-- 第一段:轮播图和课程图标 -->
<div class="nav">
<img src="img/nav.jpg" alt="">
<div class="subject">
<a href=""><i class="iconfont icon-html"></i>HTML/CSS</a>
<a href=""><i class="iconfont icon-js"></i>javaScript</a>
<a href=""><i class="iconfont icon-icon_shezhi"></i>服务端</a>
<a href=""><i class="iconfont icon-fenzuguanli"></i>数据库</a>
<a href=""><i class="iconfont icon-APPkaifa"></i>移动端</a>
<a href=""><i class="iconfont icon-icon_bangzhuwendang"></i>手册</a>
<a href=""><i class="iconfont icon-bianji"></i>工具</a>
<a href=""><i class="iconfont icon-yunhang"></i>直播</a>
</div>
</div>
<h3>推荐课程</h3>
<!-- 推荐课程两张图片 -->
<div class="class">
<img src="img/class.jpg" alt="">
<img src="img/class.jpg" alt="">
</div>
<h3>最新更新</h3>
<div class="content">
<img src="img/nav.jpg" alt="">
<div class="detail">
<span>PHP开发免费公益直播课</span>
<span>主讲:php中文网-朱老师(Peter Zhu),时间:2019年12月18日起</span>
<div class="status">
<span>初级</span>
<span>3671次播放</span>
</div>
</div>
</div>
<div class="content">
<img src="img/nav.jpg" alt="">
<div class="detail">
<span>PHP开发免费公益直播课</span>
<span>主讲:php中文网-朱老师(Peter Zhu),时间:2019年12月18日起</span>
<div class="status">
<span>初级</span>
<span>3671次播放</span>
</div>
</div>
</div>
<div class="content">
<img src="img/nav.jpg" alt="">
<div class="detail">
<span>PHP开发免费公益直播课</span>
<span>主讲:php中文网-朱老师(Peter Zhu),时间:2019年12月18日起</span>
<div class="status">
<span>初级</span>
<span>3671次播放</span>
</div>
</div>
</div>
<div class="content">
<img src="img/nav.jpg" alt="">
<div class="detail">
<span>PHP开发免费公益直播课</span>
<span>主讲:php中文网-朱老师(Peter Zhu),时间:2019年12月18日起</span>
<div class="status">
<span>初级</span>
<span>3671次播放</span>
</div>
</div>
</div>
<h3>最新文章</h3>
<div class="article">
<div class="detail">
<span>linux的终端是什么?</span>
<span>发布时间:2019-12-17</span>
</div>
<img src="img/nav.jpg" alt="">
</div>
<div class="article">
<div class="detail">
<span>linux的终端是什么?</span>
<span>发布时间:2019-12-17</span>
</div>
<img src="img/nav.jpg" alt="">
</div>
<div class="article">
<div class="detail">
<span>linux的终端是什么?</span>
<span>发布时间:2019-12-17</span>
</div>
<img src="img/nav.jpg" alt="">
</div>
</main>
<!-- 页脚,采用字体图标和文字 -->
<footer>
<span><i class="iconfont icon-daohangshouye"></i>首页</span>
<span><i class="iconfont icon-yunhang"></i>视频</span>
<span><i class="iconfont icon-quanxianshenpi"></i>社区</span>
<span><i class="iconfont icon-huiyuan2"></i>我的</span>
</footer>
</body>
</html>
CSS代码
* {
margin: 0;
padding: 0;
/* outline: 1px solid green; */
}
a {
text-decoration: none;
color: grey;
}
img {
width: 100%;
}
/* body设置为flex,垂直排列不换行 */
body {
/* min-width: 360px; */
/* max-width: 768px; */
width: 100vw;
height: 100vh;
display: flex;
flex-flow: column nowrap;
}
/* 页眉样式,黑色背景,FLEX,水平排列不换行,两端对齐,垂直居中 */
header {
height: 40px;
background-color: black;
display: flex;
justify-content: space-between;
align-items: center;
}
header > img:first-of-type {
width: 30px;
height: 30px;
border-radius: 50%;
margin: 0 0 0 5px;
}
header > img:last-of-type {
width: 94px;
}
header > i {
margin: 0 5px 0 0;
}
header > .iconfont {
font-size: 2rem;
color: white;
}
/* 主体,水平方向无滚动条,垂直方向自动滚动,水平居中FLEX,垂直排列不换行 */
main {
overflow-y: auto;
overflow-x: hidden;
display: flex;
flex-flow: column nowrap;
margin: 0 auto;
}
/* NAV包含轮播图和图标链接,FLEX,垂直不换行 */
main > .nav {
display: flex;
flex-flow: column nowrap;
}
main > .nav > img {
height: 120px;
}
/* 图标链接8个,FLEX水平换行,每个图标宽21VW,保持一行4个,两端对齐 */
main > .nav > .subject {
width: 100vw;
display: flex;
flex-flow: row wrap;
justify-content: space-around;
}
main > .nav > .subject > a {
display: flex;
flex-flow: column nowrap;
width: 21vw;
height: 8vh;
justify-content: center;
text-align: center;
}
main > .nav > .subject > a > .iconfont {
font-size: 2rem;
text-align: center;
}
main > h3 {
margin: 15px 0 5px 10px;
}
/* 推荐课程两张图片,FLEX水平不换行,分散对齐 */
main > .class {
display: flex;
flex-flow: row nowrap;
justify-content: space-around;
}
main > .class > img {
width: 45vw;
border-radius: 3px;
}
main > .content {
display: flex;
flex-flow: row nowrap;
margin: 5px;
}
main > .content > img {
width: 30vw;
margin: 0 5px;
border-radius: 3px;
}
main > .content > .detail {
display: flex;
flex-flow: column nowrap;
color: #666666;
}
main > .content > .detail > .status {
display: flex;
flex-flow: row nowrap;
justify-content: space-between;
}
main > .content > .detail span:nth-child(2) {
font-size: 0.8rem;
}
main > .content > .detail > .status span:first-of-type {
background-color: #cccccc;
padding: 3px 5px;
border-radius: 8px;
}
main > .article {
display: flex;
justify-content: space-between;
margin: 5px;
}
main > .article > .detail {
display: flex;
flex-direction: column;
flex-grow: auto;
margin: 0 5px;
}
main > .article > .detail > span:last-of-type {
font-size: 0.8rem;
}
main > .article > img {
width: 20vw;
margin: 0 5px;
border-radius: 3px;
}
footer {
/* position: fixed; */
display: flex;
height: 50px;
justify-content: space-between;
background-color: #cccccc;
}
footer span {
display: flex;
flex-flow: column nowrap;
margin: 0 20px;
}
footer > span > .iconfont {
text-align: center;
}
footer > span:first-of-type {
color: red;
}