Each and every element created using any HTML tag, is a box. The CSS box model, shows the margin, border, padding and actual space for content as different spaces, which together forms any element.
If you use Chrome Browser, press Command + Option + I
(for Mac OSX) and F10
(for Windows OS).
Select an Element...
icon, present at the top-left corner.
If you scroll down in the Styles section, you will see the Box Model representation for the selected element there.
Try hovering your mouse over the Box Model representation in the Styles section and you will see that the same will be highlighted on the actual element.
The Box Model is nothing but representation of various sections of an element box. These components/sections are:
When we use CSS to specify height and width of an element explicitly, then this height and width is for the content area of the element. While the actual space occupied by an element is inclusive of content area, padding, border and margin.
#myelement {
height:200px;
width:200px;
padding:10px;
margin:10px;
border:5px solid red;
}
For the above styling, HTML element with id
as myelement
must have a defined width and height of 200px
. But the actual height and width occupied by this element will be different, as padding, border and margin must also be considered.
Actual Width: Width(200px) + left & right padding(10px + 10px) + left and right border(5px + 5px) + left and right margin(10px + 10px) = 250px
Actual Height: Height(200px) + top & bottom padding(10px + 10px) + top and bottom border(5px + 5px) + top and bottom margin(10px + 10px) = 250px
Just like text-shadow
, the property box-shadow
is used to add a shadow to the entire element box.
Syntax:
box-shadow: <horizontal-displacement> <vertical-displacement> <blur> <color>;
blur
and color
values are not mandatory.
#box-shadow {
box-shadow: 5px 5px 5px grey;
}