Home Web Front-end CSS Tutorial CSS web button design: create a variety of cool button styles

CSS web button design: create a variety of cool button styles

Nov 18, 2023 am 10:28 AM
css button design cool button Web page style

CSS web button design: create a variety of cool button styles

CSS web button design: Create various cool button styles, specific code examples are required

In web design, buttons are a very important element because It is not only the link between users and the website, but also increases the overall visual effect and user experience. A good button style must not only have an attractive appearance, but also take into account some functional details, such as click effects, hover effects, etc. This article will share with you some CSS button design techniques and cool styles, as well as provide code examples, hoping to help you better design buttons and add more creativity to websites and applications.

1. Basic CSS button

First, let’s take a look at the most basic CSS button style:

HTML code:

1

<button class="btn">Click me</button>

Copy after login

CSS style:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

.btn {

  background-color: #4CAF50;

  border: none;

  color: white;

  padding: 10px 20px;

  text-align: center;

  text-decoration: none;

  display: inline-block;

  font-size: 16px;

  margin: 4px 2px;

  cursor: pointer;

}

 

.btn:hover {

  background-color: #3e8e41;

}

Copy after login

This button has a green background, white text and rounded borders. When the mouse hovers over the button, the background color changes to dark green, achieving a simple hover effect. This button style can basically be applied to most scenarios.

2. 3D stereoscopic effect button

Let’s create a 3D stereoscopic effect button:

HTML code:

1

<button class="btn-3d">Click me</button>

Copy after login

CSS style:

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

.btn-3d {

    border: none;

    color: #fff;

    font-size: 25px;

    line-height: 1;

    margin: 20px;

    padding: 10px 20px;

    position: relative;

    text-align: center;

    text-shadow: rgba(0,0,0,.4) 1px 1px;

    transform-style: preserve-3d;

    transition: all .3s ease-out;

    background: linear-gradient(to bottom, #556270 0%,#616161 100%);

    background-color: #556270;

}

 

.btn-3d:before,

.btn-3d:after {

    border: none;

    content: '';

    position: absolute;

    top: calc(50% - 2px);

    left: 0;

    height: 4px;

    width: 100%;

    transform-style: preserve-3d;

    transition: all .3s ease-out;

}

 

.btn-3d:before {

    background: #BD3F32;

    transform: translateZ(-1px);

    box-shadow: 0 0 8px rgba(189,63,50,.7);

}

 

.btn-3d:after {

    background: #3F7FBC;

    transform-origin: left;

    transform: rotateY(90deg) translateZ(-1px);

    box-shadow: 0 0 8px rgba(63,127,188,.7);

}

 

.btn-3d:hover {

    background: linear-gradient(to bottom, #BD3F32 0%,#616161 100%);

    transform: translateZ(-6px);

    text-shadow: none;

    box-shadow: 0 0 8px rgba(0,0,0,.5);

}

 

.btn-3d:hover:before {

    transform: translateZ(-13px) rotateY(60deg);

}

 

.btn-3d:hover:after {

    transform: rotateY(-60deg) translateZ(-13px);

    transition-delay: .05s;

}

Copy after login

This button style has an obvious 3D three-dimensional appearance effect and a translation/rotation effect in the hover state, which not only brings a visual impact to the user, but also increases the user experience.

3. Background change button

The button style below provides users with better visual cues through the gradient change of the background color:

HTML code:

1

<button class="btn-change">Click me</button>

Copy after login

CSS style:

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

.btn-change {

    cursor: pointer;

    display: inline-block;

    margin: .5rem;

    padding: .75rem 1.5rem;

    position: relative;

    text-align: center;

    text-transform: uppercase;

}

 

.btn-change:before {

    border-right: 1px solid white;

    content: "";

    height: 100%;

    left: 0;

    position: absolute;

    top: 0;

    transform: skew(-15deg) scaleY(1.4);

    width: 0;

}

 

.btn-change:hover:before {

    width: 100%;

    transition: all .3s ease;

}

 

.btn-change:after {

    border-left: 1px solid white;

    content: "";

    height: 100%;

    position: absolute;

    right: 0;

    top: 0;

    transform: skew(15deg) scaleY(1.4);

    width: 0;

}

 

.btn-change:hover:after {

    width: 100%;

    transition: all .3s ease;

    transition-delay: .15s;

}

Copy after login

The characteristic of this button style is that the background color changes more gradually in the hover state, which can better guide the user visually.

4. Hollow-out effect button

Next, we will create a very cool hollow-out effect button style:

HTML code:

1

<button class="btn-void">Click me</button>

Copy after login

CSS style :

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

.btn-void {

    border: solid 2px #bada55;

    background: none;

    color: #bada55;

    font-size: 18px;

    font-weight: bold;

    padding: 12px 24px;

    position: relative;

    transition: all .35s;

    overflow: hidden;

}

 

.btn-void:before,

.btn-void:after {

    content: "";

    position: absolute;

    top: 50%;

    left: 50%;

    transform: translate(-50%, -50%);

    background: #bada55;

    transition: all .35s;

}

 

.btn-void:before {

    height: 0%;

    width: 100%;

}

 

.btn-void:after {

    height: 100%;

    width: 0%;

}

 

.btn-void:hover,

.btn-void:focus,

.btn-void:active {

    border-color: #bada55;

    color: #fff;

}

 

.btn-void:hover:before,

.btn-void:focus:before,

.btn-void:active:before {

    height: 100%;

}

 

.btn-void:hover:after,

.btn-void:focus:after,

.btn-void:active:after {

    width: 100%;

}

Copy after login

The characteristic of this button style is that in the hover state, a white border appears around the button, the rectangular area inside the button turns white, and the button text turns green. When the whole is restored, there is a gradient effect.

5. Loading button

Finally, let’s look at a button style with loading status:

HTML code:

1

<button class="btn-loading">Submit</button>

Copy after login

CSS style:

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

.btn-loading {

  background-color: #4CAF50;

  border: none;

  color: white;

  padding: 10px 20px;

  text-align: center;

  text-decoration: none;

  display: inline-block;

  font-size: 16px;

  margin: 4px 2px;

  cursor: pointer;

  position: relative;

}

 

.btn-loading:after {

  content: "";

  position: absolute;

  top:50%;

  left: 50%;

  border: 6px solid #e6e6e6;

  border-radius: 50%;

  width: 50px;

  height: 50px;

  margin-left: -25px;

  margin-top: -25px;

  border-top-color: #3498db;

  animation: spin 2s linear infinite;

  display: none;

}

 

@keyframes spin {

  0% {

    transform: rotate(0deg);

  }

  100% {

    transform: rotate(360deg);

  }

}

 

.btn-loading.loading:after {

  display: block;

}

Copy after login

The characteristic of this button style is that after clicking the submit button, the button content will be hidden, and a rotating animation will appear to remind the user that it is loading. The overall effect is relatively intuitive.

Summary

Through the introduction of the above five button styles, we can clearly see that a good button not only needs attractive visual effects, but also needs to pay attention to some functional details, such as Changes in hover state, interaction after click, etc. The button styles provided in this article are all written based on CSS and can be easily applied in actual projects. When writing web pages, you can pay more attention to the implementation of some special effects and create buttons that better suit your needs.

The above is the detailed content of CSS web button design: create a variety of cool button styles. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Vue 3 Vue 3 Apr 02, 2025 pm 06:32 PM

It&#039;s out! Congrats to the Vue team for getting it done, I know it was a massive effort and a long time coming. All new docs, as well.

Building an Ethereum app using Redwood.js and Fauna Building an Ethereum app using Redwood.js and Fauna Mar 28, 2025 am 09:18 AM

With the recent climb of Bitcoin’s price over 20k $USD, and to it recently breaking 30k, I thought it’s worth taking a deep dive back into creating Ethereum

Can you get valid CSS property values from the browser? Can you get valid CSS property values from the browser? Apr 02, 2025 pm 06:17 PM

I had someone write in with this very legit question. Lea just blogged about how you can get valid CSS properties themselves from the browser. That&#039;s like this.

A bit on ci/cd A bit on ci/cd Apr 02, 2025 pm 06:21 PM

I&#039;d say "website" fits better than "mobile app" but I like this framing from Max Lynch:

Stacked Cards with Sticky Positioning and a Dash of Sass Stacked Cards with Sticky Positioning and a Dash of Sass Apr 03, 2025 am 10:30 AM

The other day, I spotted this particularly lovely bit from Corey Ginnivan’s website where a collection of cards stack on top of one another as you scroll.

Using Markdown and Localization in the WordPress Block Editor Using Markdown and Localization in the WordPress Block Editor Apr 02, 2025 am 04:27 AM

If we need to show documentation to the user directly in the WordPress editor, what is the best way to do it?

Comparing Browsers for Responsive Design Comparing Browsers for Responsive Design Apr 02, 2025 pm 06:25 PM

There are a number of these desktop apps where the goal is showing your site at different dimensions all at the same time. So you can, for example, be writing

Why are the purple slashed areas in the Flex layout mistakenly considered 'overflow space'? Why are the purple slashed areas in the Flex layout mistakenly considered 'overflow space'? Apr 05, 2025 pm 05:51 PM

Questions about purple slash areas in Flex layouts When using Flex layouts, you may encounter some confusing phenomena, such as in the developer tools (d...

See all articles