首页 > 其他 > 详细

利用伪元素单个颜色实现 hover 和 active 时的明暗变化效果

时间:2016-10-16 00:48:49      阅读:287      评论:0      收藏:0      [点我收藏+]

1.颜色小tip知识

  在背景色上方叠加一个黑色半透明层 rgba(0,0,0,.2) 可以得到一个更暗的颜色

  在背景色上方叠加一个白色半透明层 rgba(255,255,255,.2) 可以得到一个更亮的颜色

技术分享

单个颜色实现 hover 和 active 时的明暗变化效果

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>单个颜色实现 hover 和 active 时的明暗变化效果</title>
    <style type="text/css">   
        a {
            text-decoration: none;
        }
        .rubby {
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%,-50%);
            width: 260px;
            text-align: center;
            padding: 40px;
            font-size: 200%;
            font-weight: bolder;
            background-color: #00aabb;
            color: #fff;
            cursor: pointer;
            border-radius: 1em;
        }

        .rubby:before {
            position: absolute;
            left: 0;
            top: 0;
            right: 0;
            bottom: 0;
            border-radius: 1em;
            background-color: rgba(255,255,255,.2);
            z-index: -1;
        }
        .rubby:hover:before {
            content: "";
        }
        .rubby:after {
            position: absolute;
            left: 0;
            top: 0;
            right: 0;
            bottom: 0;
            background-color: rgba(0,0,0,.3);
            border-radius: 1em;
            z-index: -1;
        }
        .rubby:active:after {
            content: "";
        }

    </style>
</head>
<body>
    <a href="#none" class="rubby">.Rubby</a>
</body>
</html>

文章转载

【CSS进阶】伪元素的妙用--单标签之美

利用伪元素单个颜色实现 hover 和 active 时的明暗变化效果

原文:http://www.cnblogs.com/zjf-1992/p/5946339.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!