special thanks to Jan Michelfeit & Martin Kruliš
position:
float:
display: inline-block
display: flexbox
display: grid
Value | Example |
---|---|
inline |
<span> |
inline-block
|
<input> |
block |
<div> |
none |
not laid out at all |
table-cell |
<td> |
… |
<span>
does not respect width, height, and vertical padding/margin,
<img>
and <div>
do
<span>
or <img>
flow as lines,
<div>
starts a new "line"<span>
can be broken across linesinline-block
?
Download this HTML document and fix TODOs in the source code.
Usage
position
property with values
relative
, absolute
,
fixed
, and static
left
, right
,
top
, bottom
, and z-index
Example:
left:20px; top:20px
Positioned element moved relative to the original position according to left/right/top/bottom
Rest of the layout as if not positioned.
Example:
left:20px; top:20px
Positioned element moved relative to the closest positioned ancestor. Rest of layout as if the positioned element is not present. This implies that parent block does not increase size to encompass the element and the element may overflow.
Element moved relative to the viewport and it doesn't move when scrolling. Rest of layout as if the positioned element is not present.
absolute
and fixed
relative
Download this HTML document and fix TODOs in the source code.
The result should look like this.
Download this HTML document and fix TODOs in the source code(or use this codepen ).
The result should look like this.
float
property with values left
,
right
, none
clear
clear
property can have values left
,
right
, both
, none
-moz-
, -webkit-
, -ms-
, …)
Download
this HTML document
and fix TODOs in the source code
or use this codepen.
The result should look like this.
Hint: margin
property is often useful when creating a layout