flex pc端布局
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>flex三列布局</title>
<style>
/* 初始化 */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
a {
text-decoration: none;
color: cornflowerblue;
}
body {
display: flex;
flex-flow: column nowrap;
width: 1100px;
margin: auto;
}
header,
footer {
height: 50px;
border: 1px solid;
}
header {
display: flex;
/* justify-content: center; */
align-items: center;
}
header > a {
flex: 0 1 120px;
text-align: center;
}
header > a:first-of-type {
margin-right: 80px;
}
header > a:last-of-type {
margin-left: auto;
}
header > a:hover:not(:first-of-type) {
color: crimson;
}
/* 内容区布局 */
.container {
display: flex;
min-height: 600px;
justify-content: space-between;
}
.container > aside {
flex: 0 0 200px;
}
.container > main {
flex: 0 0 600px;
}
footer {
display: flex;
flex-flow: column nowrap;
text-align: center;
}
aside {
background-color: greenyellow;
}
main {
background-color: khaki;
}
/* 媒体查询 */
@media screen and (max-width: 900px) {
aside:last-of-type {
display: none;
}
.container > main {
flex: auto;
}
}
@media screen and (max-width: 650px) {
footer,
aside,
header > a:not(:first-of-type) {
display: none;
}
}
</style>
</head>
<body>
<header>
<a href="">LOGO</a>
<a href="">首页</a>
<a href="">分类</a>
<a href="">新闻</a>
<a href="">产品</a>
<a href="">登录</a>
</header>
<div class="container">
<aside>左侧</aside>
<main>内容区</main>
<aside>右侧</aside>
</div>
<footer>
<p>。。。。。。版权所有 ©苏cc 8888-9999</p>
<p>地址:江苏省苏州市金枫路888号</p>
</footer>
</body>
</html>
运行结果
移动端布局
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>移动端flex</title>
<link rel="stylesheet" href="iconfont/iconfont.css" />
<link rel="stylesheet" href="icon01.css" />
<script src="iconfont/iconfont.js"></script>
<style>
* {
margin: 0;
padding: 0;
}
a {
text-decoration: none;
color: #666;
}
html {
width: 100vw;
height: 100vh;
font-size: 14px;
color: #666;
}
body {
min-width: 360px;
background-color: #fff;
display: flex;
flex-flow: column nowrap;
}
body > header {
display: flex;
width: 95vw;
color: white;
background-color: #333;
justify-content: space-between;
height: 30px;
align-items: center;
padding: 0 15px;
position: fixed;
}
body > .slider {
height: 180px;
}
body > .slider > img {
width: 100%;
}
nav {
height: 200px;
display: flex;
flex-flow: row wrap;
align-content: space-around;
margin-top: 20px;
}
nav > div {
display: flex;
width: 25vw;
flex-flow: column nowrap;
align-items: center;
}
nav > div img {
width: 50%;
}
nav > div > a:first-of-type {
text-align: center;
}
.title {
margin-top: 10px;
font-size: 1.2rem;
font-weight: normal;
text-align: center;
}
.hot-goods {
display: flex;
margin-top: 10px;
font-size: 0.8rem;
flex-flow: row wrap;
}
.hot-goods img {
width: 100%;
}
.hot-goods > .goods-img {
padding: 10px;
box-sizing: border-box;
flex: 1 0 30vw;
display: flex;
flex-flow: column nowrap;
justify-content: center;
}
.hot-goods > .goods-img > div {
display: flex;
justify-content: space-between;
}
.list-goods {
display: flex;
flex-flow: column nowrap;
margin-top: 10px;
font-size: 0.8rem;
padding: 10px;
box-sizing: border-box;
border-top: 1px solid #555;
}
.list-goods > .goods-desc {
display: flex;
margin: 10px;
}
.list-goods > .goods-desc a {
padding: 10px;
box-sizing: border-box;
}
.list-goods > .goods-desc a:hover {
color: skyblue;
}
.list-goods img {
width: 100%;
}
footer {
display: flex;
position: fixed;
bottom: 0;
height: 55px;
width: 100vw;
background-color: ghostwhite;
border-top: 1px solid #ccc;
justify-content: space-around;
align-items: center;
}
footer > a {
display: flex;
flex-direction: column;
align-items: center;
}
footer > a:hover {
color: chocolate;
}
footer > a > span:first-of-type {
font-size: 1.8rem;
}
.goods-img > div >span:last-of-type {
font-size: 1.5rem;
}
.goods-img > div >span:nth-of-type(2) {
font-size: 1.5rem;
}
</style>
</head>
<body>
<header>
<a href="">LOGO</a>
<span class="iconfont"></span>
</header>
<div class="slider">
<img src="image/shop1.jpg" alt="" />
</div>
<nav>
<div>
<a href=""
><svg class="icon" aria-hidden="true">
<use xlink:href="#icon-1"></use></svg
></a>
<a href="">男宝宝</a>
</div>
<div>
<a href=""
><svg class="icon" aria-hidden="true">
<use xlink:href="#icon-9"></use></svg
></a>
<a href="">女宝宝</a>
</div>
<div>
<a href=""
><svg class="icon" aria-hidden="true">
<use xlink:href="#icon-4"></use></svg
></a>
<a href="">连体衣</a>
</div>
<div>
<a href=""
><svg class="icon" aria-hidden="true">
<use xlink:href="#icon-7"></use></svg
></a>
<a href="">裤子</a>
</div>
<div>
<a href=""
><svg class="icon" aria-hidden="true">
<use xlink:href="#icon-2"></use></svg
></a>
<a href="">袜子</a>
</div>
<div>
<a href=""
><svg class="icon" aria-hidden="true">
<use xlink:href="#icon-6"></use></svg
></a>
<a href="">连衣裙</a>
</div>
<div>
<a href=""
><svg class="icon" aria-hidden="true">
<use xlink:href="#icon-8"></use></svg
></a>
<a href="">裙子</a>
</div>
<div>
<a href=""
><svg class="icon" aria-hidden="true">
<use xlink:href="#icon-5"></use></svg
></a>
<a href="">团购</a>
</nav>
<h2 class="title">热销商品</h2>
<div class="hot-goods">
<div class="goods-img">
<a href=""><img src="image/dou.jpg" alt="" /></a>
<p>巴布豆</p>
<div>
<span>99 元</span>
<span class="iconfont"></span>
<span class="iconfont"></span>
</div>
</div>
<div class="goods-img">
<a href=""><img src="image/dou.jpg" alt="" /></a>
<p>巴布豆</p>
<div>
<span>99 元</span>
<span class="iconfont"></span>
</div>
</div>
<div class="goods-img">
<a href=""><img src="image/dou.jpg" alt="" /></a>
<p>巴布豆</p>
<div>
<span>99 元</span>
<span class="iconfont"></span>
</div>
</div>
</div>
</div>
<h2 class="title">
商品列表<a href=""><img src="image/logo.jpg" height="17vw" alt="" /></a>
</h2>
<div class="list-goods">
<div class="goods-desc">
<a href=""><img src="image/yf.jpg" alt="" height="130vw" /></a>
<a href=""
>男童T恤2020秋装新款假两件宝宝长袖上衣小童打底衫儿童洋气衣服............................</a
>
</div>
<div class="goods-desc">
<a href=""><img src="image/yf.jpg" alt="" height="130vw" /></a>
<a href=""
>男童T恤2020秋装新款假两件宝宝长袖上衣小童打底衫儿童洋气衣服..........................</a
>
</div>
<div class="goods-desc">
<a href=""><img src="image/yf.jpg" alt="" height="130vw" /></a>
<a href=""
>男童T恤2020秋装新款假两件宝宝长袖上衣小童打底衫儿童洋气衣服..........................</a
>
</div>
</div>
<footer>
<a href="">
<span class="iconfont hot"></span>
<span>首页</span>
</a>
<a href="">
<span class="iconfont hot"></span>
<span>分类</span>
</a>
<a href="">
<span class="iconfont hot"></span>
<span>订单</span>
</a>
<a href="">
<span class="iconfont hot"></span>
<span>客服</span>
</a>
</footer>
</body>
</html>
运行结果