2019.12.27作业
移动端m.php.cn布局(flex)实现
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>1227作业</title>
<link rel="stylesheet" href="../static/font/iconfont.css">
<link rel="stylesheet" href="PC-PAGE.css">
</head>
<body>
<header>
<a href=""><i class="iconfont icon-huiyuan2"></i>登录</a>
<img src="../static/images/logo.png" alt="">
<a href=""><i class="iconfont"></i></a>
</header>
<main>
<header><img src="../static/images/ad/ad2.jpg" alt="" height="100%"></header>
<nav>
<a href=""><img src="../static/images/01.png" alt="" height="80" width="80"><span>PS</span></a>
<a href=""><img src="../static/images/02.png" alt="" height="80" width="80"><span>C++</span></a>
<a href=""><img src="../static/images/03.png" alt="" height="80" width="80"><span>ANDROID</span></a>
<a href=""><img src="../static/images/04.png" alt="" height="80" width="80"><span>JAVA</span></a>
<a href=""><img src="../static/images/01.png" alt="" height="80" width="80"><span>PS</span></a>
<a href=""><img src="../static/images/02.png" alt="" height="80" width="80"><span>C++</span></a>
<a href=""><img src="../static/images/03.png" alt="" height="80" width="80"><span>ANDROID</span></a>
<a href=""><img src="../static/images/04.png" alt="" height="80" width="80"><span>JAVA</span></a>
</nav>
<section>
<h2>最近消息</h2>
<article>
<section><img src="../static/images/shop/9.jpg" alt="" width="100%"></section>
<section>2020年1月十大最新热门笔记本电脑</section>
</article>
<article>
<section><img src="../static/images/shop/9.jpg" alt="" width="100%"></section>
<section>2020年1月十大最新热门笔记本电脑</section>
</article>
<article>
<section><img src="../static/images/shop/9.jpg" alt="" width="100%"></section>
<section>2020年1月十大最新热门笔记本电脑</section>
</article>
<article>
<section><img src="../static/images/shop/9.jpg" alt="" width="100%"></section>
<section>2020年1月十大最新热门笔记本电脑</section>
</article>
<article>
<section><img src="../static/images/shop/9.jpg" alt="" width="100%"></section>
<section>2020年1月十大最新热门笔记本电脑</section>
</article>
<article>
<section><img src="../static/images/shop/9.jpg" alt="" width="100%"></section>
<section>2020年1月十大最新热门笔记本电脑</section>
</article>
<article>
<section><img src="../static/images/shop/9.jpg" alt="" width="100%"></section>
<section>2020年1月十大最新热门笔记本电脑</section>
</article>
<article>
<section><img src="../static/images/shop/9.jpg" alt="" width="100%"></section>
<section>2020年1月十大最新热门笔记本电脑</section>
</article>
</section>
</main>
<footer>
<a href=""><i class="iconfont"></i></a>
<a href=""><i class="iconfont"></i></a>
<a href=""><i class="iconfont"></i></a>
</footer>
</body>
</html>
css样式
*{
margin: 0;
/*padding: 0;outline: 1px dashed;*/
}
body{
display: flex;
flex-direction: column;
min-width: 360px;
height: 100vh;
width: 100vw;
}
body > header {
display: flex;
flex-direction: row;
height: 8vh;
width: 100vw;
min-width: 360px;
background-color: black;
box-sizing: border-box;
}
body > header > a {
text-decoration: none;
font-size: 16px;
color: white;
flex: 1;
margin: auto;
}
body > header > a > i {
margin-left: 3px;
margin-right: 3px;
}
body > header > a:last-of-type {
display: flex;
justify-content: flex-end;
margin-right: 3px;
}
body > main {
flex-grow: 1;
overflow: auto;
display: flex;
flex-direction: column;
}
body > main > header{
display: flex;
flex-direction: column;
}
body > main > header > img {
align-self: center;
padding: 1px;
}
body > main > nav {
align-self: center;
display: flex;
flex-wrap: wrap;
flex-direction: row;
width: 400px;
}
body > main > nav > a {
display: flex;
flex-direction: column;
text-decoration: none;
flex-basis: 80px;
flex-grow: 1;
}
body > main > nav > a > img{
align-self: center;
}
body > main > nav > a > span{
font-size: 20px;
color: black;
align-self: center;
}
body > main > section {
/*display: flex;*/
border-top: 1px lightgray solid;
margin: 5px;
}
body > main > section > article{
background-color: lightcyan;
box-shadow: 0 0 2px #888888;
margin: 1vh 0;
display: flex;
}
body > main > section > article > section:first-of-type {
width: 24vw;
height: 10vh;
display: flex;
}
body > main > section > article > section:first-of-type>img{
align-self: center;
margin-left: 1vw;
height: 8vh;
}
body > main > section > article > section:last-of-type {
flex: 1;
background-color: lightcyan;
margin: 0 1vw;
box-shadow: 0 0 2px lightgray;
align-self: center;
padding-left: 30px;
}
body > footer {
display: flex;
flex-direction: row;
height: 8vh;
width: 100vw;
min-width: 360px;
background-color: black;
box-sizing: border-box;
justify-content: space-around;
}
body > footer > a{
color: white;
align-self: center;
text-decoration: none;
}
总结,移动端页面的特点是头尾固定,中间主体滑动,在设计页面的时候,要将整个页面显示高度先设定好body{height:100vh;}
,再将头尾显示高度设定好,中间主体部分添加滑动轴main{overflow: auto;}
,一次完成基础的页面布置。注意两个单位:vh(显示高度),vw(显示宽度),二者都是百分比单位,是当前页面百分比。