| layout | post |
|---|---|
| title | CSS <strong>border</strong> |
| subtitle | The <strong>edges</strong> of the rectangle |
| section | css |
Because an HTML element is rendered as a rectangle, it can have up to 4 borders: top, bottom, left and right. You can set a border on all sides at once, or on each side individually.
A CSS border has 3 properties:
border-colordefined by using a color unitborder-stylecan be solid, dashed, dotted...border-widthdefined by using a size unit
It also has 4 possible sides:
border-topborder-bottomborder-leftborder-right
{% highlight css %} blockquote{ border-color: yellow; border-style: solid; border-width: 1px;} {% endhighlight %}
The shorthand property border allows to define all 3 properties at once:
{% highlight css %} blockquote{ border: 1px solid yellow;} {% endhighlight %}
If you want to set a border on only one of the four sides, you need to include the border's position in the CSS property. For example, for a bottom border, you can write:
{% highlight css %} blockquote{ border-bottom-color: yellow; border-bottom-style: solid; border-bottom-width: 1px;} {% endhighlight %}
As for the border property, each side has its shorthand version:
{% highlight css %} blockquote{ border-bottom: 1px solid yellow;} {% endhighlight %}
As you would have guessed, the quickest way to have 3 borders is to set all 4 of them and then remove the one you don't want:
{% highlight css %} blockquote{ border: 1px solid yellow; border-left: none;} {% endhighlight %}
Because there exist 3 border properties and 4 border locations, there are 12 combinations possible:
| border | border-color | border-style | border-width |
|---|---|---|---|
| border-top | border-top-color | border-top-style | border-top-width |
| border-bottom | border-bottom-color | border-bottom-style | border-bottom-width |
| border-left | border-left-color | border-left-style | border-left-width |
| border-right | border-right-color | border-right-style | border-right-width |
That's a lot of CSS properties available. You'll usually end up using the 5 shorthand versions only:
borderborder-topborder-bottomborder-leftborder-right