bugl
bugl
HomeLearnPatternsSearch
HomeLearnPatternsSearch

Loading lesson path

Learn/CSS/Advanced Styling
CSS•Advanced Styling

CSS Button Hover Effects

This page covers CSS button hover effects, shadows, disabled states, and width.

CSS Hoverable Buttons

The CSS

Formula

:hover pseudo - class is used to change the style of a button when you mouse over it.

Tip:

Use the CSS

Formula

transition - duration property to determine the speed of the "hover" effect:

Green

Blue

Red

Grey

Black

Example

Hoverable buttons:.button {

transition-duration: 0.4s;
}.button:hover {
background-color: #4CAF50; /* Green */
color: white;
}

CSS Buttons With Shadow

The CSS

Formula

box - shadow property is used to add a shadow to a button:

Shadow Button

Shadow on hover

Example

Formula

Buttons with shadows:.button1 {box - shadow:0 8px 16px 0 rgba(0,0,0,0.6)}.button2:hover
{box-shadow:0 8px 16px 0 rgba(0,0,0,0.6)}

CSS Disabled Button

The CSS

opacity property can be used to add transparency to a button (creates a "disabled" look).

Tip:

You can also add the cursor property with a value of

Formula

"not - allowed", which will display a "no parking sign" when you mouse over the button:

Disabled Button

Example

A disabled button:.disabledbtn {
opacity: 0.6;
cursor: not-allowed;
}

CSS Button Width

By default, the size of a button is determined by its text content.

The CSS

width property can be used to define a specific width for a button.

Tip:

Use pixels to set a fixed width, or percent for a responsive width (e.g. 50% of its parent element). 250px 50% 100%

Previous

CSS Styling Buttons

Next

CSS Button Groups