下面是总结的css技巧,建议大家收藏,以后用的时候就不用到处查资料了。当然这些也不是所有的,大家如果有什么好的css有趣样式技巧也可以发出来哦
最常见的一种形状了。切图,不存在的。
/** 正三角 */ .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; }css自带的border-style属性 dotted/ dashed . 效果展示出来太密了,并不符合UI设计
具体的虚线的颜色和间距都可以通过repeating-linear-gradient生成的条纹背景去调整。
单行文本
.single-ellipsis{ width: 500px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }多行文本
.multiline-ellipsis { display: -webkit-box; word-break: break-all; -webkit-box-orient: vertical; -webkit-line-clamp: 4; //需要显示的行数 overflow: hidden; text-overflow: ellipsis; }扩展: -webkit-line-clamp 是一个 不规范的属性(unsupported WebKit property),它没有出现在 CSS 规范草案中。
为了实现该效果,它需要组合其他外来的WebKit属性。常见结合属性:
display: -webkit-box; 必须结合的属性 ,将对象作为弹性伸缩盒子模型显示 。-webkit-box-orient 必须结合的属性 ,设置或检索伸缩盒对象的子元素的排列方式 。text-overflow,可以用来多行文本的情况下,用省略号“…”隐藏超出范围的文本 。浏览器兼容性:
html结构
<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()函数 用来计算css属性的值。
用法:
/** 属性:calc(expression)*/ 宽度:calc(100% - 34px);除了减法,还可以用 +(加) ,/(除) , *(乘)。但要注意的是:
注意: +和-运算符在运算符和值之间需要一个空格。例如,它将被calc(50% -8px)解释为百分比,后跟负像素长度。只有在-到8px之间有空格时,才可以正确减法:calc(50% - 8px) 空格在乘法或除法中不起作用,但建议阅读时要注意。
浏览器兼容性:
没有什么是一个flex搞不定的。
.parent{ display: flex; }如果一行放不下,可以折行。
.parent{ flex-wrap: wrap; }上面是一些静态的样式,还有一些更好玩的动态样式,希望有机会与大家分享~ 如果你有更多css的有趣技巧,欢迎在评论区留言哦~
对了,小编为大家准备了一套2020最新的web前端资料,需要点击下方链接获取方式
学习前端,你掌握这些。二线也能轻松拿8K以上