hooyantsing's Blog

P173_22_使用skew制作炫酷按钮

字数统计: 211阅读时长: 1 min
2020/04/22

P173 22 使用skew制作炫酷按钮

实战案例

介绍:当鼠标移动到btn时出现平行四边形颜色背景。

效果:

5f9c6dea476ebbdc0a0483805cabb4db.png

源码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        * {
            padding: 0;
            margin: 0;
            box-sizing: border-box;
        }

        body {
            height: 100vh;
            width: 100vw;
            display: flex;
            justify-content: center;
            align-items: center;
            background: #2c3e50;
        }

        main {
            width: 200px;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        main a {
            color: white;
            font-size: 1.5em;
            text-decoration: none;
            border: solid 3px #e74c3c;
            flex: 1;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 55px;
            position: relative;
            overflow: hidden;
        }

        .btn::after {
            content: '';
            width: 0;
            height: 100%;
            position: absolute;
            transform: skew(45deg);
            background: #e74c3c;
            z-index: -1;
            transition: .5s;
        }

        .btn:hover::after {
            width: 100%;
        }
    </style>
</head>
<body>
<main>
    <a href="" class="btn">houdunren</a>
</main>
</body>
</html>
CATALOG