通过css的before和after制作按钮的动画效果

看了下面网站的按钮效果,想自己也试试。

http://tympanus.net/Development/CreativeLinkEffects/

按照上面网站的效果实现。

1.左右两侧出现边框的效果。相见代码如下:

html代码:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="../css/config.css" media="screen" title="no title" charset="utf-8">
</head>
<body>

<a href="#" class="button">
    home
</a>
<a href="#" class="button"> project </a>

</body>
</html>

 less代码:

@charset "UTF-8";

html,body{
    margin:0px;
    padding: 0px;
    height: 100%;
}

//伪类before after的联系
.button{
    display: inline-block;
    padding:10px 20px 10px 20px;
    position: relative;
    cursor: pointer;
    &::before,&::after{
        display: inline-block;
        opacity: 0;
        .button-transion();
    }
    &::before{
        content: "[";
        .button-translate(10px);
    }
    &::after{
        content: "]";
        .button-translate(-10px);
    }
    &:hover::before{
        .button-translate(0px);
        opacity: 1;
    }
    &:hover::after{
        .button-translate(0px);
        opacity: 1;
    }
    .button-transion{
        -moz-transition: all 0.3s linear;
        -webkit-transition: all 0.3s linear;
        -o-transition: all 0.3s linear;
        transition: all 0.3s linear;
    }
    .button-translate(@c){
        -moz-transform:translate(@c,0);
        -webkit-transform:translate(@c,0);
        -o-transform: translate(@c,0);
        transform:translate(@c,0);
    }
}

 

2.鼠标移动上移文字效果

html代码:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>css3 动画按钮 demo3</title>
<link rel="stylesheet" href="../css/config.css" media="screen" title="no title" charset="utf-8">
</head>
<body>
    <div style="margin:20px">
        <a href="#" class="button3" >
            <span text="home">home</span>
        </a>
        <a href="#" class="button3">
            <span text="project">project</span>
        </a>
    </div>
</body>
</html>

 less代码:

//伪类before after的联系
.button3{
    color:#000;
    text-decoration: none;
    margin:5px 10px 5px 10px;
    display: inline-block;
    overflow: hidden;
    height: 30px;
    line-height: 30px;

    span{
        display: block;
        .common-transion(all,0.3s,linear,0s);
    }
    span::after{
        content: attr(text);
        display: block;
        font-weight: bold;
    }
    &:hover{
        span{
            .trasform-translate(0px,-50%);
        }
    }

}

 3.鼠标移动出现下划线动画

html代码:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>css3 动画按钮 demo2</title>
<link rel="stylesheet" href="../css/config.css" media="screen" title="no title" charset="utf-8">
</head>
<body>
    <div style="margin:20px">
        <a href="#" class="button2"> home </a>
        <a href="#" class="button2"> project </a>
    </div>
</body>
</html>

 css代码:

//伪类before after的联系
.button2{
    color:#000;
    text-decoration: none;
    margin:5px 10px 5px 10px;
    padding:10px;
    display: inline-block;

    &::after{
        height:2px;
        width: 100%;
        background: #000;
        display: block;
        content: "";
        opacity: 0;
        .trasform-translate(0px,10px);
        .common-transion(all,0.3s,linear,0s);
    }

    &:hover::after{
        opacity: 1;
        .trasform-translate(0px,5px);
    }


}

 

转载于:https://www.cnblogs.com/screw/p/5151919.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值