Everything in a web page has a box around it. These boxes are mostly invisible but they control how everything is arranged and laid out on the page. We call this the CSS Box Model.
Each box has:
Let's take a look at CSS Borders first. Here are some examples of <div></div>
elements that have different borders applied to them using CSS.
The border-style
CSS property sets the style of border to use on the box. The following values can be set for border-style
:
xxxxxxxxxx
<div style="border-style: dotted;">A dotted border.</div>
<div style="border-style: dashed;">A dashed border.</div>
<div style="border-style: solid;">A solid border.</div>
<div style="border-style: double;">A double border.</div>
<div style="border-style: groove;">A groove border.</div>
<div style="border-style: ridge;">A ridge border.</div>
<div style="border-style: inset;">An inset border.</div>
<div style="border-style: outset;">An outset border.</div>
<div style="border-style: none;">No border.</div>
<div style="border-style: hidden;">A hidden border.</div>
xxxxxxxxxx
div{
margin-bottom: 10px;
}
The border-width
CSS property sets how wide (usually in pixels) the border is.
xxxxxxxxxx
<div style="border-style: dotted; border-width: 3px;">A dotted border.</div>
<div style="border-style: dashed; border-width: 6px;">A dashed border.</div>
<div style="border-style: solid; border-width: 15px;">A solid border.</div>
xxxxxxxxxx
div{
margin-bottom: 10px;
}
We can also set different widths for each of the top, right, bottom and left borders by providing 4 values for the border-width
CSS property in the following order:
xxxxxxxxxx
<div style="border-style: solid; border-width: 10px 5px 20px 40px;">A solid border.</div>
The border-color
CSS property sets the colour of the border. The values we can use to set the colour can be:
xxxxxxxxxx
<div style="border-style: dotted; border-width: 5px; border-color: red;">A dotted border using a colour name.</div>
<div style="border-style: dashed; border-width: 5px; border-color: #0000FF;">A dashed border using a HEX value.</div>
<div style="border-style: solid; border-width: 5px; border-color: rgb(0,255,100); ">A solid border using a RGB value.</div>
<div style="border-style: solid; border-width: 5px; border-color: transparent;">A solid border with a transparent colour.</div>
xxxxxxxxxx
div{
margin-bottom: 10px;
}