CSS3 Borders
CSS3 Borders
With CSS3, you can create rounded borders, add shadow boxes, and use images as borders without using a design program such as Photoshop.
In this chapter you will learn about the following border properties:
- border-radius
- box-shadow
- border-image
CSS3 Rounded Corners
Adding rounded corners in CSS2 was tricky. We had to use a different image for each corner.
In CSS3, it is easy to create rounded corners.
In CSS3 the border-radius property is used to create rounded corners:
This is a rounded border!
Example
Add rounded corners to a div element:
div
{
border:2px solid;
border-radius:25px;
}
Try it »
CSS3 Box Shadow
The box-shadow property in CSS3 is used to add shadows:
Example
Add the box-shadow property to a div
div
{
box-shadow: 10px 10px 5px #888888;
}
Try it »
CSS3 Border Images
With the CSS3 border-image property, you can use an image to create a border:
The border-image property allows you to specify an image as a border! The original image used to create the border above:
Create a border with an image in a div:
Example
Create a border with an image in a div
div
{
border-image:url(border.png) 30 30 round;
-webkit-border-image:url(border.png) 30 30 round; /* Safari 5 and older */
-o-border-image:url(border.png) 30 30 round; /* Opera */
}
Try it »
New Border Properties
| property | Description | CSS |
|---|---|---|
| border-image | Shorthand property for setting all the border image properties. | 3 |
| border-radius | A shorthand property for setting all four border-*-radius properties | 3 |
| box-shadow | Attaches one or more drop shadows to a box | 3 |