CSS常用技巧
背景图高斯模糊且全屏显示
- css3高斯滤镜
filter:blur(Pixels)
```vbscript-html
```scss
.normal{
width: 400px;
height: 300px;
background: url(https://image.ibb.co/mTuQAd/deploy_success.png);
background-size: 100% 100%;
display: inline-block;
margin: 100px 30px;
}
.blur {
filter: blur(3px)
}
背景图片模糊,文字不模糊
<div class="blur">
<div class="wrap"></div>
<div class="text">文字不模糊</div>
</div>
.blur{
position: relative;
width: 400px;
height: 300px;
border: 1px solid #ccc;
}
.wrap {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: url(https://image.ibb.co/mTuQAd/deploy_success.png);
background-size: 100% 100%;
filter: blur(3px);
}
.text {
position: absolute;
color: brown;
font-size: 36px;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
z-index: 10;
}
垂直水平居中
- 绝对定位 + 已知宽高
.box { position:absulote; top:50%; left:50%; margin-left:-(box容器宽度的一半); margin-top:-(box容器高度的一半); }
- 绝对定位 + 未知宽高
.box { position:absulote; top:50%; left:50%; transform: translate(-50%, -50%); }
- Flex布局
.box{ display:flex; align-items: center; justify-content: center; }
loading…效果
<div class="loading"></div>
.loading{
width: 400px;
height: 300px;
position: relative;
border: 1px solid #ccc;
}
.loading::before{
content: '';
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 30px;
height: 30px;
border-top: 3px solid #c53333;
border-bottom: 3px solid #96da81;
border-left: 3px solid #5d8fa7;
border-right: 3px solid #9b5981;
border-radius: 50%;
animation: spin 2s linear infinite;
}
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {transform: rotate(360deg)}
}
tip提示(三角形)
<div class="tip top"></div>
<div class="tip bottom"></div>
<div class="tip left"></div>
<div class="tip right"></div>
.tip{
width: 200px;
height: 100px;
border-radius: 4px;
background-color: #383838;
position: relative;
display: inline-block;
margin-top: 100px;
margin-left: 30px;
}
.tip::before{
content: '';
position: absolute;
height: 0;
width: 0;
border: 20px solid transparent;
}
.top::before{
top: 0%;
left: 50%;
transform: translate(-50%, -100%);
border-bottom: 20px solid #383838;
}
.bottom::before{
top: 100%;
left: 50%;
transform: translate(-50%, 0%);
border-top: 20px solid #383838;
}
.left::before{
top: 50%;
left: 0;
transform: translate(-100%, -50%);
border-right:20px solid #383838;
}
.right::before{
top: 50%;
left: 100%;
transform: translate(0%, -50%);
border-left:20px solid #383838;
}
样式重置
html,body,div,h1,h2,h3,h4,h5,h5,ul,ol,li,p,span,strong,em,i,img,dl,dt,dd,table,tr,th,td,
address,abbr,circle,cite,code,embed,iframe,input,image,label,menu,nav,object,pre,select,
tbody,textarea,tfoot,thead,title,video{
padding: 0;
margin: 0;
border: 0;
font: inherit;
vertical-align: baseline;
outline: none;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
html { height: 101%; }
body {
font-size: 62.5%;
line-height: 1;
font-family: Arial,Tahoma, sans-serif;
}
article, aside, details, figcaption,
figure, footer, header, hgroup, menu,
nav, section {
display: block;
}
blockquote, q { quotes: none; }
blockquote:before, blockquote:after,
q:before, q:after {
content: ''; content: none;
}
ol, ul { list-style: none; }
strong { font-weight: bold; }
table { border-collapse: collapse; border-spacing: 0; }
img { border: 0; max-width: 100%; }
p { font-size: 1.2em; line-height: 1.0em; color: #333; }
a {text-decoration: none}
display:block | none切换时的动画
<body>
<div class="header">
<span class="line"></span>
<ul class="list-wrap">
<li class="list-item">全部作品</li>
<li class="list-item">全新体验</li>
<li class="list-item">最新动态</li>
</ul>
<span class="line"></span>
</div>
<div class="body">
<div class="list-item active">1</div>
<div class="list-item">2</div>
<div class="list-item">3</div>
</div>
</body>
.header {
display: flex;
justify-content: center;
align-items: center;
}
.header .line {
display: block;
width: 390px;
height: 1px;
background-color: #ddd;
}
.header .list-wrap {
margin: 0 35px;
display: flex;
}
.header .list-item {
cursor: pointer;
font-size: 18px;
color: #333;
position: relative;
}
.header .list-item:not(:last-child) {
padding-right: 30px;
}
.header .list-item::before {
position: absolute;
content: "";
width: 4px;
height: 4px;
background: #ddd;
border-radius: 50%;
left: 84%;
top: 38%;
}
.body{
margin-top: 30px;
}
.body .list-item {
display: none;
width: 600px;
height: 400px;
background: #ddd;
border-radius: 10px;
margin: auto;
color: #fff;
font-size: 100px;
text-align: center;
line-height: 400px
}
.body .active{
display: block;
animation: activeIdx 0.3s ease-in;
}
@keyframes activeInx{
0%{opacity: 0.5;}
100%{opacity: 1;}
}
css - 导航条hover样式由中间向两边扩散
<body>
<div class="nav">
<div class="list-wrap">
<li class="list-item">首页</li>
<li class="list-item">博客</li>
<li class="list-item">团队介绍</li>
<li class="list-item">项目介绍</li>
<li class="list-item">体验试用</li>
<li class="list-item">合作联系</li>
</div>
</div>
</body>
.nav{
height: 140px;
background-color: #070707;
margin: 200px auto;
}
.list-wrap{
display: flex;
justify-content: center;
height: 100%;
align-items: center;
}
.list-item{
list-style: none;
color:#fff;
cursor: pointer;
position: relative;
margin-right: 100px
}
.list-item::after, .list-item::before{
position: absolute;
content: '';
top: 125%;
left: 56%;
width: 0%;
height: 3px;
background-color: #3e82f7;
transition: all .2s ease-in;
}
.list-item:hover::after {
width: 60%;
left: 50%;
}
.list-item:hover::before{
width: 60%;
left: -10%
}