Mon Sep 12 2022

Border Animation

CSS979 views

File Name: animated-button-border.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Animated Button Border</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        body {
            background-color: #292929;
        }

        section {
            display: flex;
            justify-content: center;
            align-items: center;
            width: 100%;
            height: 100vh;
        }

        a {
            color: #fff;
            text-decoration: none;
            font-size: 30px;
            padding: 8px 15px;
            position: relative;
        }

        a::before {
            position: absolute;
            content: '';
            z-index: -1;
            width: 0;
            height: 100%;
            top: 0;
            left: 50%;
            border: 2px solid transparent;
            transition: 0.3s all ease-in-out;
        }

        a::after {
            position: absolute;
            content: '';
            z-index: -1;
            width: 100%;
            height: 0;
            top: 50%;
            left: 0;
            border: 2px solid transparent;
            transition: 0.3s all ease-in-out;
        }

        a:hover::before,
        a:hover::after {
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
        }

        a::before {
            border-top-color: #fff;
            border-bottom-color: #fff;
        }

        a::after {
            border-left-color: #fff;
            border-right-color: #fff;
        }
    </style>
</head>
<body>
    <section>
        <a href="">Hover Me</a>
    </section>
</body>
</html>

Result Screenshot(s)

Border AnimationWorking Sample0

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.