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

Linux Dig command usage

Dig Introduction: Dig is a tool that queries DNS ...

CSS method of controlling element height from bottom to top and from top to bottom

Let’s start the discussion from a common question...

Use CSS content attr to achieve mouse hover prompt (tooltip) effect

Why do we achieve this effect? ​​In fact, this ef...

Examples of using temporary tables in MySQL

I've been a little busy these two days, and t...

7 Best VSCode Extensions for Vue Developers

Adding the right VS Code extension to Visual Stud...

MySQL isolation level detailed explanation and examples

Table of contents 4 isolation levels of MySQL Cre...

How to implement digital paging effect code and steps in CSS

A considerable number of websites use digital pagi...

Solve the problem of resetting the Mysql root user account password

Problem description: The following error message ...

Get / delete method to pass array parameters in Vue

When the front-end and back-end interact, sometim...

Simple web design concept color matching

(I) Basic concepts of web page color matching (1) ...

CSS imitates Apple's smooth switch button effect

Table of contents 1. Code analysis 2. Source code...

Mini Program implements custom multi-level single-select and multiple-select

This article shares the specific code for impleme...

Summary of the use of CSS scope (style splitting)

1. Use of CSS scope (style division) In Vue, make...

Use h1, h2, and h3 tags appropriately

In the process of making web pages, it is inevita...