- 清除浮動
文檔元素浮動情況下,會出現(xiàn)各種問題,這時候需要清除浮動:
.clearfix:after {
content: ".";
display: block;
clear: both;
visibility: hidden;
line-height: 0;
height: 0;
}
.clearfix { display: inline-block; }
html[xmlns] .clearfix { display: block; }
* html .clearfix { height: 1%; }
- 文本省略顯示...
文本超過一定寬度時,需要顯示省略號。
單行省略(需要設置外層寬度):
.text-overflow {
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
多行省略(css多行省略在chrome生效需要設置高度、寬度):
.text-overflow-more {
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
}
- 透明效果,兼容不同瀏覽器
.transparent {
filter: alpha(opacity=50); /* internet explorer */
-khtml-opacity: 0.5; /* khtml, old safari */
-moz-opacity: 0.5; /* mozilla, netscape */
opacity: 0.5; /* fx, safari, opera */
}
-
制作三角形,三角形效果如下:
三角形
.triangle {
border-color: transparent transparent green transparent;
border-style: solid;
border-width: 0px 300px 300px 300px;
height: 0px;
width: 0px;
}
- 禁止換行, 文字只在一行內顯示不換行
.nowrap {white-space:nowrap;}
- 文字漸變效果
.text-gradient{
background-image: linear-gradient(135deg, deeppink, deepskyblue);
-webkit-background-clip: text;
color: transparent;
}
- 背景漸變
.gradient{
background: #e6e6e6; //當瀏覽器不支持背景漸變時該語句將會被執(zhí)行
background: -o-linear-gradient(top, #fdfdfd, #e6e6e6);
background: -moz-linear-gradient(top, #fdfdfd, #e6e6e6);
background: -webkit-linear-gradient(top, #fdfdfd, #e6e6e6); //最新發(fā)布語法
background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#fdfdfd), #e6e6e6); //老式語法
}
-
下劃線動效,鼠標移動到文字時出現(xiàn)下劃線效果,效果如下:
下劃線動效
.hover-underline-animation {
display: inline-block;
position: relative;
color: #0087ca;
}
.hover-underline-animation::after {
content: '';
position: absolute;
width: 100%;
transform: scaleX(0);
height: 2px;
bottom: 0;
left: 0;
background-color: #0087ca;
transform-origin: bottom right;
transition: transform 0.25s ease-out;
}
.hover-underline-animation:hover::after {
transform: scaleX(1);
transform-origin: bottom left;
}
-
甜甜圈loading效果, 效果如下:
甜甜圈loading
@keyframes donut-spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
.donut {
display: inline-block;
border: 4px solid rgba(0, 0, 0, 0.1);
border-left-color: #7983ff;
border-radius: 50%;
width: 50px;
height: 50px;
animation: donut-spin 1.2s linear infinite;
}
-
彈跳的loading,效果如下:
彈跳的loading
<div class="bouncing-loader">
<div></div>
<div></div>
<div></div>
</div>
@keyframes bouncing-loader {
from {
opacity: 1;
transform: translateY(0);
}
to {
opacity: 0.1;
transform: translateY(-1rem);
}
}
.bouncing-loader {
display: flex;
justify-content: center;
}
.bouncing-loader div {
width: 1rem;
height: 1rem;
margin: 3rem 0.2rem;
background: #8385aa;
border-radius: 50%;
animation: bouncing-loader 0.6s infinite alternate;
}
.bouncing-loader div:nth-child(2) {
animation-delay: 0.2s;
}
.bouncing-loader div:nth-child(3) {
animation-delay: 0.4s;
}



