- Box model
-
Every element in web design is a retangular box (CSS Tricks)
Every element in web design is a retangular box (CSS Tricks)
size
width
width + padding-left + padding-right + border-left + border-right
height
height + padding-top + padding-bottom + border-top + border-bottom
Content box
inline-size
and
block-size
or width
and height
Padding box
padding
sits around the content as white space
padding
and related properties
Border box
border box
wraps the content and any padding; size it using
border and related properties
Margin box
margin
is the outermost layer, wrapping the
content
, padding
, and border as whitespace between
this box and other elements
margin
and related propertiesinner display
type and an outer display
type
block
then:
width
and height
properties are respected
Padding
, margin
and border
will cause other
elements to be pushed away from the box
width
is not specified, the box will extend in the inline direction to
fill the space
available in its container
h1
and p
, use block as their outer
display type by default
inline
, then:
width
and height
properties will not apply
Top
and bottom
padding
, margins
, and
borders
will apply but will not cause other inline boxes to move away from
the box
Left
and right
padding
, margins
, and
borders
will apply and will cause other inline boxes to move away from the
box
a
, span
, em
and
strong
use inline as their outer display type by default
display: flex;
block
but this changes
the inner
display
type to flex
flex items
and behave according
to the Flexbox specification
inline-size
CSS property defines the horizontal or vertical size
of an element's block, depending on its writing
mode
inline-size
relates to
the height of
the element;
inline-size
relates to
the width of
the element;