参考

  • loading
  • hover
  • animate
  • 30s code

    0.5px 细线边框

    1. .box {
    2. position: relative;
    3. ::before {
    4. content: "";
    5. position: absolute;
    6. width: 200%;
    7. height: 200%;
    8. border: 1px solid transparent;
    9. /* transform-origin: 0 0; */
    10. transform: scale(0.5, 0.5);
    11. box-sizing: border-box;
    12. border-radius: 185px;
    13. }
    14. }

    滚动穿透

    1. toggleForbidScrollThrough(isForbide) {
    2. if (isForbide) {
    3. this.scrollTop =
    4. document.body.scrollTop || document.documentElement.scrollTop
    5. // position fixed会使滚动位置丢失,所以利用top定位
    6. document.body.style.position = 'fixed'
    7. document.body.style.top = `-${this.scrollTop}px`
    8. document.body.style.left = 0
    9. document.body.style.right = 0
    10. } else {
    11. // 恢复时,需要还原之前的滚动位置
    12. document.body.style.position = 'static'
    13. document.body.style.top = '0px'
    14. window.scrollTo(0, this.scrollTop)
    15. }
    16. }

    number输入框上下箭头

    1. input::-webkit-outer-spin-button,
    2. input::-webkit-inner-spin-button {
    3. -webkit-appearance: none;
    4. }
    5. input[type="number"] {
    6. -moz-appearance: textfield;
    7. }

    多行溢出隐藏

    1. display: -webkit-box; /*弹性伸缩盒子模型*/
    2. -webkit-box-orient: vertical; /*伸缩盒子子排列方式*/
    3. -webkit-line-clamp: 3; /*设置显示文本行数*/
    4. text-overflow: ellipsis;
    5. overflow: hidden;

    box-sizing

    1. html {
    2. box-sizing: border-box;
    3. }
    4. *,
    5. *:before,
    6. *:after {
    7. box-sizing: inherit;
    8. }

    CSS实现 - 三角形

    1. border: 50px solid transparent;
    2. border-bottom: 150px solid green;

    滚动条抖动问题

    1. .box {
    2. padding-right: calc(100vw - 100%);
    3. }

    100vw 为 视窗宽度,100%为内容宽度,100vw - 100 % 为 滚动条宽度。margin-right 也可以。

隐藏 空元素

  1. // 作用于所有节点
  2. :empty {
  3. display: none;
  4. }

文字类

文字镂空

  1. h1 {
  2. display: inline-block;
  3. color: inherit;
  4. line-height: 1.2;
  5. font-size: 60px;
  6. background: linear-gradient(to right, rgb(0, 225, 180), rgb(1, 201, 218));
  7. -webkit-text-stroke: 4px transparent;
  8. -webkit-background-clip: text;
  9. -webkit-text-fill-color: inherit;
  10. }

@font-face 字体多源

  1. 声明多个源

    1. @font-face {
    2. font-family: 'DroidSerif';
    3. src: url('DroidSerif-Regular-webfont.ttf') format('truetype');
    4. font-weight: normal;
    5. font-style: normal;
    6. }
    7. @font-face {
    8. font-family: 'DroidSerif';
    9. src: url('DroidSerif-Italic-webfont.ttf') format('truetype');
    10. font-weight: normal;
    11. font-style: italic;
    12. }
    13. @font-face {
    14. font-family: 'DroidSerif';
    15. src: url('DroidSerif-Bold-webfont.ttf') format('truetype');
    16. font-weight: bold;
    17. font-style: normal;
    18. }
    19. @font-face {
    20. font-family: 'DroidSerif';
    21. src: url('DroidSerif-BoldItalic-webfont.ttf') format('truetype');
    22. font-weight: bold;
    23. font-style: italic;
    24. }
  2. 使用

    1. body { font-family:"DroidSerif", Georgia, serif; }
    2. h1 { font-weight:bold; }
    3. em { font-style:italic; }
    4. strong em {
    5. font-weight:bold;
    6. font-style:italic;
    7. }

    相关链接:@font-face tip: define font-weight and font-style

其他