EN
CSS - create button with hover effect
0 points
In this article, we would like to show you how to create a button with a hover effect using CSS.
Quick solution:
xxxxxxxxxx
1
button:hover {
2
background: red; /* changes background color on hover */
3
}
The :hover
CSS pseudo-class is triggered when the user hovers over an element with the cursor, changing the element style to the one specified within curly brackets.
In this example, we change color of the button
element with the following steps:
- in
button
style, we specify the button's style at the beginning and use thetransition
property to smoothly change the style of thebutton
element over0.5
second, - we use
button:hover
pseudo-class to add or overwrite existingbutton
styles on the hover event.
xxxxxxxxxx
1
2
<html>
3
<head>
4
<style>
5
6
button {
7
color: white;
8
height: 75px;
9
width: 75px;
10
border: 2px solid #0086b3;
11
border-radius: 5px;
12
background: deepskyblue;
13
transition: 0.5s;
14
}
15
16
button:hover {
17
background: #33ccff;
18
box-shadow: 0px 0px 5px 5px rgba(0, 172, 230, 0.3);
19
}
20
21
</style>
22
</head>
23
<body>
24
<button>Click me.</button>
25
</body>
26
</html>