Sample code for implementing a background gradient button using div+css3

Sample code for implementing a background gradient button using div+css3

As the demand for front-end pages continues to increase, some scenes require gradient background elements. This article uses div and new css3 attributes to implement a button with a gradient background, as follows:

1.background: linear-gradient The background is a gradient color attribute
2. Use the animation feature in CSS3 to change the background from left to right (color_move)
3. To achieve the gradient effect, extend the width of the background to 400%

Above code:

html:

<div class="btn_demo">
	<div class="text">Experience</div>
	<div class="arrow">»</div>
</div>

css:

@keyframes arrow_move {
   /* Start state */
    0% {
        left: 130px;
    }
	/* End status */
    100% {
        left: 140px;
    }
}
@keyframes color_move {
    /* Start state */
    0% {
        background-position: 0% 0%; /* horizontal position vertical position */
    }
    50% {
        background-position: 50% 0%;
    }
	/* End status */
    100% {
        background-position: 100% 0%;
    }
}
.btn_demo {
    width:180px;
    height:60px;
    border-radius: 10px;
    position: relative;
    background: linear-gradient( 90deg, #373d42 0%, #2679dd 50%, #373d42 100%);
    background-size: 400% 100%;
    animation: color_move 5s infinite ease-in-out alternate;
    cursor: pointer;
}
.btn_demo:hover {
    background: #2679dd;
}
.btn_demo:active {
    background: #373d42;
}
.btn_demo > .text {
    /* background: yellow; */
    width: 50px;
    text-align: center;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%,-50%);
    font-size: 20px;
    color: #fff;
    font-weight: bold;
}
.btn_demo > .arrow {
    /* background: green; */
    width: 20px;
    text-align: center;
    position: absolute;
    font-size: 30px;
    color: #fff;
    top: 46%;
    transform: translateY(-50%);
    left: 130px; /* move 130~150px */
    /* Call animation */
    animation-name: arrow_move;
    /* Duration */
    animation-duration: 1s;
    /* Infinite playback*/
    animation-iteration-count: infinite;
}

The effect is as follows:


This concludes this article about using div+css3 to implement a button with a gradient background. For more div+css3 gradient background button content, please search 123WORDPRESS.COM’s previous articles or continue browsing the following related articles. I hope you will support 123WORDPRESS.COM in the future!

<<:  CSS achieves colorful and smart shadow effects

>>:  Interview questions: The difference between the Holy Grail layout and the double-wing layout

Recommend

Example of how to configure cross-domain failure repair in nginx

Nginx cross-domain configuration does not take ef...

Detailed explanation based on event bubbling, event capture and event delegation

Event bubbling, event capturing, and event delega...

HTML uses the title attribute to display text when the mouse hovers

Copy code The code is as follows: <a href=# ti...

Handtrack.js library for real-time monitoring of hand movements (recommended)

【Introduction】: Handtrack.js is a prototype libra...

Solve the problem of combining AND and OR in MySQL

As shown below: SELECT prod_name,prod_price FROM ...

MYSQL slow query and log example explanation

1. Introduction By enabling the slow query log, M...

How to insert a link in html

Each web page has an address, identified by a URL...

Detailed tutorial on deploying SpringBoot + Vue project to Linux server

Preface Let me share with you how I deployed a Sp...

Alibaba Cloud Server Ubuntu Configuration Tutorial

Since Alibaba Cloud's import of custom Ubuntu...

MySQL implements a solution similar to Oracle sequence

MySQL implements Oracle-like sequences Oracle gen...

MySQL index leftmost principle example code

Preface I was recently reading about MySQL indexe...

Tutorial on building svn server with docker

SVN is the abbreviation of subversion, an open so...

Detailed example of HTML element blocking Flash

Copy code The code is as follows: wmode parameter...

JS realizes simple picture carousel effect

This article shares the specific code of JS to ac...

Markup Language - Phrase Elements

Click here to return to the 123WORDPRESS.COM HTML ...