Chapter 10. Borders and backgrounds with CSS3
This chapter covers
- Adding drop shadows and rounded corners
- New ways to apply and use background images
- Creating gradients with CSS
CSS3 makes the traditional background image approaches more flexible and provides declarative options for drop shadows, rounded corners, and gradients. Solutions that have involved images, JavaScript, and extra markup can be replaced with simple HTML and CSS.
The pseudo-3D effect provided by drop shadows is a popular design approach. In the past, designers have gone to great lengths to add this visual effect, but CSS3 saves a lot of time and resources by having the functionality built in.
CSS3 defines two types of shadow: box and text. They use a similar syntax:
text-shadow: rgb(0,0,0) 3px 3px 3px; box-shadow: rgb(0,0,0) 3px 3px 3px;
A basic shadow, in either case, is defined by four values:
<color> <offset-x> <offset-y> <blur-radius>
Without the optional blur-radius, a box shadow isn’t much different from a border. Here’s an example that only sets an offset-x:
box-shadow: rgb(0,0,0) 12px 0px;
And here’s a plain offset-y:
box-shadow: rgb(0,0,0) 0px 12px;
Adding a blur-radius by itself creates a more shadow-like effect, even without any offsets: