flex布局应用
1. 等高布局
flex 实现等高布局非常轻松
-
-
<html lang="en">
-
<head>
-
<meta charset="UTF-8">
-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
-
<title>Document</title>
-
</head>
-
<style>
-
.main{
-
width: 150px;
-
background-color: aqua;
-
display: flex;
-
-
}
-
.mian div{
-
background-color: pink;
-
border: 1px black solid;
-
box-sizing: border-box;
-
}
-
</style>
-
<body>
-
<div class="main">
-
<div>
-
<p>测试文字</p>
-
</div>
-
<div>
-
<p>测试文字</p>
-
<p>测试文字</p>
-
<p>测试文字</p>
-
<p>测试文字</p>
-
<p>测试文字</p>
-
<p>测试文字</p>
-
<p>测试文字</p>
-
<p>测试文字</p>
-
</div>
-
</div>
-
</body>
-
</html>
实现效果如下图所示:
2. 两列/三列布局
-
-
<html lang="en">
-
<head>
-
<meta charset="UTF-8">
-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
-
<title>Document</title>
-
</head>
-
<style>
-
.main{
-
width: 500px;
-
height: 500px;
-
background-color: red;
-
display: flex;
-
}
-
.main div:nth-of-type(1){
-
width: 200px;
-
background-color: aqua;
-
}
-
.div2{
-
background-color: yellow;
-
flex-grow: 1;
-
}
-
-
</style>
-
<body>
-
<div class="main">
-
<div>第一列,固定宽度</div>
-
<div class="div2">第二列自适应容器宽度</div>
-
-
</div>
-
</body>
-
</html>
同理,可以设置三列布局,将作用两侧容器的宽度固定,中间部分容器宽度设置为自适应即可。
3.溢出项布局
-
-
<html lang="en">
-
<head>
-
<meta charset="UTF-8">
-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
-
<title>溢出项布局</title>
-
</head>
-
<style>
-
.main{
-
width: 100px;
-
height: 500px;
-
background-color: aqua;
-
display: flex;
-
}
-
.main div{
-
width: 150px;
-
margin-right: 10px;
-
/* 溢出项布局的关键在于,将自动收缩属性设置为0 */
-
flex-shrink: 0;
-
background-color: red;
-
}
-
</style>
-
<body>
-
<div class="main">
-
<div>1</div>
-
<div>2</div>
-
<div>3</div>
-
<div>4</div>
-
<div>5</div>
-
</div>
-
-
</body>
-
</html>
4.粘性页脚布局
当内容不满满屏时候,页脚在页面的底部,当内容满屏是,页脚紧紧跟随在内容的后面
-
-
<html lang="en">
-
<head>
-
<meta charset="UTF-8">
-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
-
<title>Document</title>
-
<style>
-
body{
-
margin: 0;
-
}
-
.main{
-
min-height: 100vh;
-
display: flex;
-
flex-direction: column;
-
}
-
.header{
-
background: skyblue;
-
height: 100px;
-
}
-
.content{
-
flex-grow: 1;
-
}
-
.footer{
-
background: red;
-
height: 100px;
-
}
-
</style>
-
</head>
-
<body>
-
<div class="mian">
-
<div class="header"></div>
-
<div class="content">
-
<p>测试内容</p>
-
<p>测试内容</p>
-
<p>测试内容</p>
-
<p>测试内容</p>
-
<p>测试内容</p>
-
<p>测试内容</p>
-
<p>测试内容</p>
-
</div>
-
<div class="footer"></div>
-
</div>
-
</body>
-
</html>
综合案例
1.轮播图
-
-
<html lang="en">
-
<head>
-
<meta charset="UTF-8" />
-
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
-
<title>轮播图</title>
-
<link rel="stylesheet" href="./icon/iconfont.css" />
-
<link rel="stylesheet" href="./icon/iconfont.json" />
-
<link rel="stylesheet" href="./icon/iconfont.ttf" />
-
<style>
-
.swiper-container {
-
position: relative;
-
}
-
.swiper-wrapper {
-
display: flex;
-
}
-
.swiper-slide {
-
width: 100%;
-
flex-shrink: 0;
-
}
-
.swiper-slide img {
-
width: 100%;
-
}
-
.swiper-pagination {
-
position: absolute;
-
height: 28px;
-
width: 100%;
-
bottom: 0;
-
display: flex;
-
justify-content: center;
-
align-items: center;
-
}
-
.swiper-pagination-bullet {
-
width: 8px;
-
height: 8px;
-
border-radius: 50%;
-
background: antiquewhite;
-
margin: 0 4px;
-
}
-
.swiper-pagination-bullet-active {
-
background: pink;
-
}
-
.swiper-button-prev{
-
position: absolute;
-
left:0;
-
top:50%;
-
display: flex;
-
align-items: center;
-
}
-
.swiper-button-next{
-
position: absolute;
-
right: 0;
-
top:50%;
-
display: flex;
-
align-items: center;
-
}
-
i{
-
font-size: 88px;
-
color: brown;
-
}
-
</style>
-
</head>
-
<body>
-
<div class="swiper-container">
-
<div class="swiper-wrapper">
-
<div class="swiper-slide"><img src="./图片/1.jpg" alt="#" /></div>
-
<div class="swiper-slide"><img src="./图片/2.jpg" alt="#" /></div>
-
<div class="swiper-slide"><img src="./图片/3.jpg" alt="#" /></div>
-
<div class="swiper-slide"><img src="./图片/4.jpg" alt="#" /></div>
-
</div>
-
<!-- 分页器 -->
-
<div class="swiper-pagination">
-
<span
-
class="swiper-pagination-bullet swiper-pagination-bullet-active"
-
></span>
-
<span class="swiper-pagination-bullet"></span>
-
<span class="swiper-pagination-bullet"></span>
-
<span class="swiper-pagination-bullet"></span>
-
</div>
-
<!-- 导航按钮 -->
-
<div class="swiper-button-prev">
-
<i class="iconfont icon-xiangzuojiantou"></i>
-
</div>
-
<div class="swiper-button-next">
-
<i class="iconfont icon-jinrujiantou"></i>
-
</div>
-
</div>
-
</body>
-
</html>
2.知乎导航栏
-
-
<html lang="en">
-
<head>
-
<meta charset="UTF-8">
-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
-
<title>Document</title>
-
<link rel="stylesheet" href="./reset.css">
-
<link rel="stylesheet" href="./icon2/iconfont.css">
-
<link rel="stylesheet" href="./icon2/iconfont.json">
-
<link rel="stylesheet" href="./icon2/iconfont.ttf">
-
<style>
-
body{
-
background: #f6f6f6;
-
}
-
.header-container{
-
background: #ffffff;
-
}
-
.header-wrapper{
-
margin: 0 auto;
-
height: 52px;
-
min-width: 1000px;
-
max-width: 1156px;
-
display: flex;
-
align-items: center;
-
}
-
.header-logo{
-
margin-right: 20px;
-
}
-
.header-nav{
-
list-style: none;
-
display: flex;
-
-
}
-
.header-nav li{
-
margin-right: 30px;
-
}
-
.header-search{
-
/* height: 20px; */
-
display: flex;
-
flex-grow: 1;
-
justify-content: center;
-
}
-
.header-search-wrapper{
-
max-width: 452px;
-
height: 34px;
-
display: flex;
-
align-items: center;
-
justify-content: space-between;
-
flex-grow: 1;
-
background: #f6f6f6;
-
border-radius: 100px;
-
}
-
.header-search-input{
-
border: none;
-
background: none;
-
margin: 0 20px;
-
}
-
.header-search-wrapper i{
-
margin: 0 20px;
-
}
-
.header-btn{
-
display: flex;
-
}
-
.header-btn-login{
-
width: 60px;
-
height: 32px;
-
border: 1px #0066ff solid;
-
border-radius: 3px;
-
color: #0066ff;
-
/* 去除按钮默认背景 */
-
background: none;
-
cursor: pointer;
-
display: block;
-
margin-left: 20px;
-
}
-
.header-btn-zhihu{
-
width: 90px;
-
height: 32px;
-
background: #0066ff;
-
color: white;
-
border: none;
-
border-radius: 3px;
-
display: block;
-
margin-left: 20px;
-
cursor: pointer;
-
}
-
</style>
-
</head>
-
<body>
-
<div class="header-container">
-
<div class="header-wrapper">
-
<div class="header-logo">
-
<a href="#"><img src="./logo.PNG" alt="#"></a>
-
</div>
-
<ul class="header-nav">
-
<li>首页</li>
-
<li>会员</li>
-
<li>发现</li>
-
<li>等你来答</li>
-
</ul>
-
<div class="header-search">
-
<div class="header-search-wrapper">
-
<input class="header-search-input" type="text" placeholder="520文案">
-
<i class="iconfont icon-fangdajing"></i>
-
</div>
-
-
</div>
-
<div class="header-btn">
-
<button class="header-btn-login">登录</button>
-
<button class="header-btn-zhihu">加入知乎</button>
-
</div>
-
</div>
-
</div>
-
</body>
-
</html>
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /boutique/detail/tanhgeicbf
系列文章
更多
同类精品
更多
-
photoshop保存的图片太大微信发不了怎么办
PHP中文网 06-15 -
Android 11 保存文件到外部存储,并分享文件
Luke 10-12 -
word里面弄一个表格后上面的标题会跑到下面怎么办
PHP中文网 06-20 -
《学习通》视频自动暂停处理方法
HelloWorld317 07-05 -
photoshop扩展功能面板显示灰色怎么办
PHP中文网 06-14 -
微信公众号没有声音提示怎么办
PHP中文网 03-31 -
excel下划线不显示怎么办
PHP中文网 06-23 -
excel打印预览压线压字怎么办
PHP中文网 06-22 -
怎样阻止微信小程序自动打开
PHP中文网 06-13 -
TikTok加速器哪个好免费的TK加速器推荐
TK小达人 10-01