参考
- loading
- hover
- animate
- 30s code
0.5px 细线边框
.box {position: relative;::before {content: "";position: absolute;width: 200%;height: 200%;border: 1px solid transparent;/* transform-origin: 0 0; */transform: scale(0.5, 0.5);box-sizing: border-box;border-radius: 185px;}}
滚动穿透
toggleForbidScrollThrough(isForbide) {if (isForbide) {this.scrollTop =document.body.scrollTop || document.documentElement.scrollTop// position fixed会使滚动位置丢失,所以利用top定位document.body.style.position = 'fixed'document.body.style.top = `-${this.scrollTop}px`document.body.style.left = 0document.body.style.right = 0} else {// 恢复时,需要还原之前的滚动位置document.body.style.position = 'static'document.body.style.top = '0px'window.scrollTo(0, this.scrollTop)}}
number输入框上下箭头
input::-webkit-outer-spin-button,input::-webkit-inner-spin-button {-webkit-appearance: none;}input[type="number"] {-moz-appearance: textfield;}
多行溢出隐藏
display: -webkit-box; /*弹性伸缩盒子模型*/-webkit-box-orient: vertical; /*伸缩盒子子排列方式*/-webkit-line-clamp: 3; /*设置显示文本行数*/text-overflow: ellipsis;overflow: hidden;
box-sizing
html {box-sizing: border-box;}*,*:before,*:after {box-sizing: inherit;}
CSS实现 - 三角形
border: 50px solid transparent;border-bottom: 150px solid green;
滚动条抖动问题
.box {padding-right: calc(100vw - 100%);}
100vw 为 视窗宽度,100%为内容宽度,100vw - 100 % 为 滚动条宽度。margin-right 也可以。
隐藏 空元素
// 作用于所有节点:empty {display: none;}
文字类
文字镂空
h1 {display: inline-block;color: inherit;line-height: 1.2;font-size: 60px;background: linear-gradient(to right, rgb(0, 225, 180), rgb(1, 201, 218));-webkit-text-stroke: 4px transparent;-webkit-background-clip: text;-webkit-text-fill-color: inherit;}
@font-face 字体多源
声明多个源
@font-face {font-family: 'DroidSerif';src: url('DroidSerif-Regular-webfont.ttf') format('truetype');font-weight: normal;font-style: normal;}@font-face {font-family: 'DroidSerif';src: url('DroidSerif-Italic-webfont.ttf') format('truetype');font-weight: normal;font-style: italic;}@font-face {font-family: 'DroidSerif';src: url('DroidSerif-Bold-webfont.ttf') format('truetype');font-weight: bold;font-style: normal;}@font-face {font-family: 'DroidSerif';src: url('DroidSerif-BoldItalic-webfont.ttf') format('truetype');font-weight: bold;font-style: italic;}
使用
body { font-family:"DroidSerif", Georgia, serif; }h1 { font-weight:bold; }em { font-style:italic; }strong em {font-weight:bold;font-style:italic;}
其他
- transform 会导致 fixed 降级 为 absolute transform 对渲染影响
- @import 是串行加载,link是并行加载
