CSS: Alignment tips
Alignment
Now that we've covered the most common CSS properties, here is a summary to how to center an element.
text-align
Text inside block level elements can be aligned with text-align
.
h1 {
/* Possible values are : left, right, center, justified*/
text-align: center;
}
margin
Another common technique for center alignement in block level elements is to use margin: 0 auto
, as explained in Margins chapter.
position
To align an element with respect to the viewport or its containing element, you can use absolute
position with left
, right
, top
, bottom
properties. See Positionning chapter.
float
You can align an element left or right inside its container with float:left
(or right). See Float chapter.