Thu Jan 05 2023

How to Create a Dual Color Button with CSS Pseudo-Elements

CSS3566 views

How to Create a Dual Color Button with CSS Pseudo-Elements

File Name: dual-color-button.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>Dual Color Button</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        body {
            background-color: #ffffff;
        }

        section {
            width: 100%;
            /* height: 100vh; */
            margin-top: 100px;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        a.btn {
            padding: 10px 30px;
            text-decoration: none;
            font-size: 24px;
            color: #292929;
            border: solid thin #9f9f9f;
            border-radius: 30px;
            position: relative;
            overflow: hidden;
        }

        a.btn::before {
            content: '';
            position: absolute;
            left: -50%;
            top: 0;
            bottom: 0;
            width: 50%;
            background-color: #ff6600;
            transition: 0.3s all ease-in-out;
            z-index: -1;
        }
        
        a.btn::after {
            content: '';
            position: absolute;
            right: -50%;
            top: 0;
            bottom: 0;
            width: 50%;
            background-color: #ffd900;
            transition: 0.3s all ease-in-out;
            z-index: -1;
        }

        a.btn:hover::before {
            left: 0;
        }

        a.btn:hover::after {
            right: 0;
        }
    </style>
</head>
<body>
    <section>
        <a href="" class="btn">Hi Everyone!</a>
    </section>
</body>
</html>

Result Screenshot(s)

How to Create a Dual Color Button with CSS Pseudo-ElementsWorking 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.