三角形
/** 正三角 */
.triangle {
width: 0;
height: 0;
border-style: solid;
border-width: 0 25px 40px 25px;
border-color: transparent transparent rgb(245, 129, 127) transparent;
}
倒三角形
/** 倒三角 */
.triangle {
width: 0;
height: 0;
border-style: solid;
border-width: 40px 25px 0 25px;
border-color: rgb(245, 129, 127) transparent transparent transparent;
}
虛線效果
image.png
.dotted-line{
border: 1px dashed transparent;
background: linear-gradient(white,white) padding-box, repeating-linear-gradient(-45deg,#ccc 0, #ccc .25em,white 0,white .75em);
}
css自帶的border-style屬性 dotted/ dashed . 效果展示出來太密了亦镶,并不符合UI設(shè)計
具體的虛線的顏色和間距都可以通過repeating-linear-gradient生成的條紋背景去調(diào)整率触。
文本超出省略號
單行文本
image.png
.single-ellipsis{
width: 500px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
多行文本
image.png
.multiline-ellipsis {
display: -webkit-box;
word-break: break-all;
-webkit-box-orient: vertical;
-webkit-line-clamp: 4; //需要顯示的行數(shù)
overflow: hidden;
text-overflow: ellipsis;
}
擴展: -webkit-line-clamp 是一個 不規(guī)范的屬性(unsupported WebKit property),它沒有出現(xiàn)在 CSS 規(guī)范草案中掏呼。
為了實現(xiàn)該效果,它需要組合其他外來的WebKit屬性计技。常見結(jié)合屬性:
- display: -webkit-box; 必須結(jié)合的屬性 涌攻,將對象作為彈性伸縮盒子模型顯示 。
- -webkit-box-orient 必須結(jié)合的屬性 怀各,設(shè)置或檢索伸縮盒對象的子元素的排列方式 倔韭。
- text-overflow,可以用來多行文本的情況下瓢对,用省略號“...”隱藏超出范圍的文本 寿酌。
瀏覽器兼容性:
image.png
時間軸
image.png
html結(jié)構(gòu)
<div class="timeline-content">
<div v-for='(item, index) in timeLine' :key='index' class="time-line">
<div :class="`state-${item.state} state-icon`"></div>
<div class="timeline-title">{{item.title}}</div>
</div>
</div>
css樣式
/** 時間軸 */
.timeline-content{
display: flex;
.time-line{
padding: 10px 10px 10px 20px;
position: relative;
&::before{
content: '';
height: 1px;
width: calc(100% - 34px);
background: #EBEBEB;
position: absolute;
left: 24px;
top: 0;
}
}
.state-icon{
width: 20px;
height: 20px;
position: absolute;
top: -12px;
left: 0;
}
.state-1{
background: url('https://static.daojia.com/assets/project/tosimple-pic/fen-zu-7-copy-6bei-fen_1589266208621.png') no-repeat;
background-size: cover;
}
.state-2{
background: url('https://static.daojia.com/assets/project/tosimple-pic/12_1589266226040.png') no-repeat;
background-size: cover;
}
.state-3{
background: url('https://static.daojia.com/assets/project/tosimple-pic/fen-zu-7-copy-3_1589266140087.png') no-repeat;
background-size: cover;
}
}
calc()函數(shù) 用來計算css屬性的值。
用法
/** 屬性:calc(expression)*/
寬度:calc(100% - 34px);
除了減法硕蛹,還可以用 +(加) 醇疼,/(除) 硕并, *(乘)。但要注意的是:
注意: +和-運算符在運算符和值之間需要一個空格秧荆。例如倔毙,它將被calc(50% -8px)解釋為百分比,后跟負像素長度乙濒。只有在-到8px之間有空格時陕赃,才可以正確減法:calc(50% - 8px) 空格在乘法或除法中不起作用,但建議閱讀時要注意颁股。
瀏覽器兼容性:
image.png
滾動條
image.png
.scroll-container {
height: 250px;
border: 1px solid #ddd;
padding: 15px;
overflow: auto;
.row {
margin: 0;
line-height: 1.5;
}
&::-webkit-scrollbar {
width: 8px;
background: white;
}
&::-webkit-scrollbar-corner, /* 滾動條角落 */
&::-webkit-scrollbar-thumb,
&::-webkit-scrollbar-track {
border-radius: 4px;
}
&::-webkit-scrollbar-corner,
&::-webkit-scrollbar-track {
/* 滾動條軌道 */
background-color: rgba(180, 160, 120, 0.1);
box-shadow: inset 0 0 1px rgba(180, 160, 120, 0.5);
}
&::-webkit-scrollbar-thumb {
/* 滾動條手柄 */
background-color: #00adb5;
}
}
卡券效果
image.png
.coupon{
width: 300px;
height: 100px;
position: relative;
background: radial-gradient(circle at right bottom, transparent 10px, #ffffff 0) top right /50% 51px no-repeat,
radial-gradient(circle at left bottom, transparent 10px, #ffffff 0) top left / 50% 51px no-repeat,
radial-gradient(circle at right top, transparent 10px, #ffffff 0) bottom right / 50% 51px no-repeat,
radial-gradient(circle at left top, transparent 10px, #ffffff 0) bottom left / 50% 51px no-repeat;
filter: drop-shadow(2px 2px 2px rgba(0,0,0,.2));
}
陰影效果
image.png
// 三角形陰影
.shadow-triangle{
width: 0;
height: 0;
border-style: solid;
border-width: 0 50px 50px 50px;
border-color: transparent transparent rgb(245, 129, 127) transparent;
filter:drop-shadow(10px 0px 10px rgba(238, 125, 55,0.5));
}
// 缺圓投影
.circle-square{
width:100px;
height:50px;
line-height: 50px;
background: radial-gradient(circle at bottom right, transparent 20px, rgb(245, 129, 127) 15px);
filter: drop-shadow(2px 2px 2px rgba(238, 132, 66, 0.9));
}
// 氣泡陰影
.tip {
width: 100px;
height: 30px;
line-height: 30px;
border: 1px solid rgb(245, 129, 127);
border-radius: 4px;
position: relative;
background-color: #fff;
filter: drop-shadow(0px 2px 4px rgba(245, 129, 127, 0.9));
&::before {
content: "";
width: 0;
height: 0;
border-style: solid;
border-width: 0 10px 10px 10px;
border-color: transparent transparent #fff transparent;
position: absolute;
top: -10px;
left: 0;
right: 0;
margin: auto;
z-index: 2;
}
&::after {
content: "";
width: 0;
height: 0;
border-style: solid;
border-width: 0 10px 10px 10px;
border-color: transparent transparent rgb(245, 129, 127) transparent;
position: absolute;
top: -11px;
left: 0;
right: 0;
margin: auto;
z-index: 1;
}
}
等高布局
image.png
沒有什么是一個flex搞不定的么库。
.parent{
display: flex;
}
如果一行放不下,可以折行甘有。
.parent{
flex-wrap: wrap;
}
總結(jié)
上面是一些靜態(tài)的樣式廊散,有的會經(jīng)常用到,特此筆錄一下梧疲。
感謝博主分享(轉(zhuǎn)載):https://juejin.im/post/5ed3c27ee51d455f9a6368c9