美文网首页
常用的css小技巧

常用的css小技巧

作者: 陆阿狸 | 来源:发表于2019-08-22 09:26 被阅读0次
  1. 清除浮动
    文档元素浮动情况下,会出现各种问题,这时候需要清除浮动:
.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%; }
  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;
}
  1. 透明效果,兼容不同浏览器
.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 */
}
  1. 制作三角形,三角形效果如下:


    三角形
.triangle {
    border-color: transparent transparent green transparent;
    border-style: solid;
    border-width: 0px 300px 300px 300px;
    height: 0px;
    width: 0px;
}
  1. 禁止换行, 文字只在一行内显示不换行
.nowrap {white-space:nowrap;}
  1. 文字渐变效果
.text-gradient{
    background-image: linear-gradient(135deg, deeppink, deepskyblue);
    -webkit-background-clip: text;
    color: transparent;
}
  1. 背景渐变
.gradient{
    background: #e6e6e6; //当浏览器不支持背景渐变时该语句将会被执行
    background: -o-linear-gradient(top, #fdfdfd, #e6e6e6);
    background: -moz-linear-gradient(top, #fdfdfd, #e6e6e6);
    background: -webkit-linear-gradient(top, #fdfdfd, #e6e6e6); //最新发布语法
    background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#fdfdfd), #e6e6e6); //老式语法
}
  1. 下划线动效,鼠标移动到文字时出现下划线效果,效果如下:


    下划线动效
.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;
}
  1. 甜甜圈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;
}
  1. 弹跳的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;
}

相关文章

  • 常用的一些 CSS 技巧三

    你可以看看其他常用的 CSS 技巧: 常用的一些 CSS 技巧(一)[https://www.jianshu.co...

  • css常用小技巧

    解决 inline-block元素设置overflow:hidden属性导致相邻行内元素项下偏移 超出部分显示省略...

  • CSS常用小技巧

    解决inline-block元素设置overflow:hidden属性导致相邻行内元素向下偏移 超出部分显示省略号...

  • 常用CSS小技巧

    一、单行文本与多行文本溢出省略 1.1 单行文本溢出 1.2 多行文本溢出 二、CSS绘制三角形 右、下三角形同理...

  • 2019-10-21

    26个常用易忘CSS小技巧收集于平时常用但易忘的CSS实现方法,如有遗漏或补充,还请指正! 解决inline-bl...

  • 常用的css小技巧

    清除浮动文档元素浮动情况下,会出现各种问题,这时候需要清除浮动: 文本省略显示...文本超过一定宽度时,需要显示省...

  • css布局和居中

    本文主要介绍了css常用的布局,居中等其他小技巧。 css布局 左右布局 利用float实现左右布局 左右模块设置...

  • Css常用技巧

    Css常用技巧 1.单行省略

  • 几个常用CSS小技巧

    1、表单标题上下字体对齐方法 项目中经常遇到各种表单,表单标题上下对齐是一个很常见的需求,但标题的字数通常并不一样...

  • 前端常用CSS小技巧

    注意:以下前缀兼容性写法注释-o-:Opera-ms://IE10-moz://火狐-webkit://Safar...

网友评论

      本文标题:常用的css小技巧

      本文链接:https://www.haomeiwen.com/subject/zeugsctx.html