CSS Buttons
In this chapter, we introduce how to use CSS to create buttons.
Basic button style
Example
background-color: #4C7EAF; /* Green */
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
}
Try it Yourself »
Button Color
We can usebackground-colorAttribute to set button color:
Example
Try it Yourself »
Button Size
We can usefont-sizeAttribute to set button size:
Example
Try it Yourself »
Rounded Button
We can useborder-radiusAttribute to set rounded button:
Example
Try it Yourself »
Button border color
We can useborderAttribute to set button border color:
Example
Try it Yourself »
Mouse hover button
We can use:hoverThe selector is used to modify the style when the mouse hovers over the button.
Tip:We can usetransition-durationThe property sets the speed of the "hover" effect:
Example
Try it Yourself »
Button Shadow
We can usebox-shadowAttribute to add shadow to button:
Example
Try it Yourself »
Disabled Button
We can useopacityThe property adds transparency to the button (looks similar to the effect of the "disabled" attribute).
Tip:We can addcursorThe property, set to "not-allowed", is used to set a disabled image:
Button Width
By default, the size of the button is determined by the text content on the button (the length matches based on the text content). We can usewidthAttribute to set button width:
Tip:If you want to set a fixed width, you can use pixels (px) as the unit; if you want to set a responsive button, you can set it as a percentage.
Button Group
Remove outer margin and addfloat:leftto set up a button group:
Button group with border
We can useborderAttribute to set bordered button group:
Example
Try it Yourself »
Button Animation
other extensionsFor more button styles, you can use the CSS button generator:https://c.example.com/front-end/6222/