A common task in CSS is the centralization of text and images.
1) Center text lines:
Centering text titles or paragraphs is the simplest and most common centralization task. Just use the text-align CSS property as shown below:
P { text-align: center }
H2 { text-align: center }
The CSS rules shown render each horizontal-centered line of P or H2.
2) Center a block of text or an image:
Another task of centralization is to center not a text, but a block as a whole. Put another way: set left and right margins equal to a block. To get this effect we use the'auto' value for the margin property. It is necessary that the block has a fixed width, because in the case of flexible blocks it will assume the total width available. Note the following example:
P.blocktext {
margin-left: auto;
margin-right: auto;
width: 6em
}
...
<P class="blocktext">Esse bloco de texto...
This is also the technique used to center an image: set the block level for the image and the auto value for the left and right margins, as shown below:
IMG.displayed {
display: block;
margin-left: auto;
margin-right: auto }
...
<IMG class="displayed" src="..." alt="...">
In summary, although suggestive, text-align
aligns objects and not only text.
I hope I’ve helped
Would your "<i>" be the image in this case? Because in this case, it is only an icon source so it will center as a source.
– Kamile Pimenta
Sam, whoops I’ll always forget ;)
– Leandro Nascimento