CSS Properties
Border
The CSS property border can be used to add border to an element. We
can specify a common border for the entire element on all sides, but
we also have the option of specifying borders invividually for each
side of the default rectangular HTML elements.
Common attributes
| Attribute | Description | Required |
|---|---|---|
| style | the style of the border (none, solid, dotted, dashed, double, groove, ridge, inset, outset) | yes (defaults to none) |
| width | the width of the border [length unit] | no (defaults to medium) |
| color | the color of the border [color] | no (defaults to the current color of the element) |
Code example: shorthand
.all-style {border: solid;}.all-style-color {border: dotted red;}.all-width-style {border: 1em solid;}.all-width-style-color {border: 1em double #d32f2f;}
which produces
.all-style
.all-style-color
.all-width-style
.all-width-style-color
Code example: extended
.rainbow {/* top right bottom left */border-width: 0.2em 0.4em 0.6em 0.8em;border-color: red orange yellow green;border-style: solid dashed double dotted;}
which produces
.rainbow
By using the extended properties we can specify borders for each side in more detail.
Code example: border radius
We can round out our sharp corners with a CSS property called border-radius.
.rounded {border: 0.5em solid black;/* all equivalent *//* all sides */border-radius: 1em;/* top/bottom right/left */border-radius: 1em 1em;/* top right bottom left */border-radius: 1em 1em 1em 1em;}
which produces
.rounded
Read more on MDN
border
Test yourself
Description
Add the class
black-border
to the .quote <div> element. Remember that we can add multiple
classes to the same element by separating them with spaces.
All relevant rules and declarations have been defined for you.
Tests
- 1
Your
<div>element should have the classblack-borderappended to it. - 2
Your
<div>element should still have the classquote.
Preview