All HTML Elements Can Be Considered As Boxes. in CSS, The Term "Box Model" Is Used When Talking About Design and Layout
All HTML Elements Can Be Considered As Boxes. in CSS, The Term "Box Model" Is Used When Talking About Design and Layout
Box Model
All HTML elements can be considered as boxes. In CSS, the term "box model" is used when talking about
design and layout.
Box model
CSS Borders:
Property
Description
border
border-width
border-color
border-style
Sets the style of the four borders. (Values are listed below)
border-left
border-top
border-right
border-bottom
border-bottom-color
border-bottom-style
border-bottom-width
border-left-color
border-left-style
border-left-width
border-right-color
border-right-style
CSS 2.1
Box Model
border-right-width
border-top-color
border-top-style
border-top-width
border-style: dotted;
CSS 2.1
Box Model
Border Outline:
An outline is a line that is drawn around elements (outside the borders) to make the element "stand out".
outline-color
outline-width
CSS Margins:
The margin property defines the space around an HTML element. It is possible to use negative values to overlap
content.
Property
Description
margin
margin-bottom
margin-left
margin-right
margin-top
Examples:
<p style="margin: 15px; border:1px solid black;">All four margins will be 15px </p>
<p style="margin:10px 2%; border:1px solid black;">Top and bottom margin will be 10px, left and right margin will
be 2% of the total width of the document. </p>
<p style="margin: 10px 2% -10px; border:1px solid black;"> Top margin will be 10px, left and right margin will be
2% of the total width of the document, bottom margin will be -10px </p>
<p style="margin: 10px 2% -10px auto; border:1px solid black;">Top margin will be 10px, right margin will be 2% of
the total width of the document, bottom margin will be -10px, left margin will be set by the browser </p>
CSS Padding:
The padding clears an area around the content (inside the border) of an element. The padding is affected by the
background color of the element.
Property
padding
Description
A shorthand property for setting all the padding properties in one declaration
3
CSS 2.1
Box Model
padding-bottom
padding-left
padding-right
padding-top
Examples:
<p style="padding: 15px; border:1px solid black;">All four padding will be 15px </p>
<p style="padding:10px 2%; border:1px solid black;"> Top and bottom padding will be 10px, left and right padding
will be 2% of the total width of the document. </p>
<p style="padding: 10px 2% 10px; border:1px solid black;"> Top padding will be 10px, left and right padding will be
2% of the total width of the document, bottom padding will be 10px </p>
<p style="padding: 10px 2% 10px 10px; border:1px solid black;">Top padding will be 10px, right padding will be 2%
of the total width of the document, bottom padding and top padding will be 10px </p>
CSS Dimensions
The CSS dimension properties allow you to control the height and width of an element.
The max-height property is used to set a maximum height that a box can be.
The min-height property is used to set the minimum height that a box can be.
The max-width property is used to set the maximum width that a box can be.
The min-width property is used to set the minimum width that a box can be.
Example:
<p style="width:400px; height:100px;border:1px solid red;padding:5px; margin:10px;line-height:30px;"> This is
Demo This is Demo This is Demo This is Demo This is Demo This is Demo This is Demo This is Demo This is Demo
This is Demo This is Demo This is Demo This is Demo This is Demo </p>