怎么在CSS3中利用transition属性实现下划线?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

专注于为中小企业提供成都做网站、网站制作、成都外贸网站建设服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业罗平免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了上千企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。
transition属性
- transition: 简写属性,用于在一个属性中设置四个过渡属性。 
- transition-property: 规定应用过渡的 CSS 属性的名称。 
- transition-duration: 定义过渡效果花费的时间。默认是 0。 
- transition-timing-function: 规定过渡效果的时间曲线。默认是 "ease"。 
- linear: 规定以相同速度开始至结束的过渡效果(等于 cubic-bezier(0,0,1,1)) 
- ease: 规定慢速开始,然后变快,然后慢速结束的过渡效果(cubic-bezier(0.25,0.1,0.25,1)) 
- ease-in: 规定以慢速开始的过渡效果(等于 cubic-bezier(0.42,0,1,1)) 
- ease-out: 规定以慢速结束的过渡效果(等于 cubic-bezier(0,0,0.58,1)) 
- ease-in-out: 规定以慢速开始和结束的过渡效果(等于 cubic-bezier(0.42,0,0.58,1)) 
- cubic-bezier(n,n,n,n): 在 cubic-bezier 函数中定义自己的值。可能的值是 0 至 1 之间的数值。 
- transition-delay: 规定过渡效果何时开始。默认是 0。 
transition: width 1s linear 2s; /*简写实例*/
/*等同如下*/ transition-property: width; transition-duration: 1s; transition-timing-function: linear; transition-delay: 2s;
tranform属性
- translate() 根据左(X轴)和顶部(Y轴)位置给定的参数,从当前元素位置移动。 
- rotate() 在一个给定度数顺时针旋转的元素。负值是允许的,这样是元素逆时针旋转。 
- scale() 该元素增加或减少的大小,取决于宽度(X轴)和高度(Y轴)的参数: 
- skew() 包含两个参数值,分别表示X轴和Y轴倾斜的角度,如果第二个参数为空,则默认为0,参数为负表示向相反方向倾斜。 
- matrix() matrix 方法有六个参数,包含旋转,缩放,移动(平移)和倾斜功能。 
实现我们需要的效果
当然,在这就直接放出代码,代码中有注释方便理解
/*css代码*/
h3{
    position: relative;
    padding: 15px;
    text-align: center;    
}
button{
    width: 100px;
    height: 40px;
    border-radius: 15px;
    border: none;
    background: #188FF7;
    color: #fff;
    outline: none;
    cursor: pointer;
    font-weight: bold;
}
button:hover{
    background: #188EA7;
}
.container{
    width: 600px;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 0 auto;
    
}
.line{
    position: absolute;
    left: 0;
    bottom: 0;
    height: 3px;
    width: 100%;
    transition: transform .5s;
    background: #188EA7;
    color: #188EA7;
    transform: scaleX(0);
    z-index: 1111;            
}
@keyframes changeColor1{
    from{
        color: #000;
    }
    to{
        color: #188EA7;
    }
}
@keyframes changeColor2{
    from{                
        color: #188EA7;
    }
    to{
        color: #000;
    }
}
    
        百度前端学院
        
    
    
//js部分代码
(function () {
    let btn = document.getElementById('change');
    let h3 = document.getElementById('title');
    let line = document.getElementById('line');
    let count = 0;
    btn.onclick = function () {
        if(count%2===0){
            line.style.transform = "scaleX(1)";
            h3.style.animation = "changeColor1 1s";
            h3.style.color = "#188EA7";
            count++;
        }else{
            line.style.transform = "scaleX(0)";
            h3.style.animation = "changeColor2 1s";
            h3.style.color = "#000";
            count++;
        }
        
    }
})();看完上述内容,你们掌握怎么在CSS3中利用transition属性实现下划线的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注创新互联行业资讯频道,感谢各位的阅读!
新闻标题:怎么在CSS3中利用transition属性实现下划线
文章路径:http://www.scyingshan.cn/article/pjeseg.html

 建站
建站
 咨询
咨询 售后
售后
 建站咨询
建站咨询 
 