Ejemplo 1: centro de alineación CSS
//HTML
<div class="parent">
Hello World</span>
</div>
//CSS
.parent {
display: flex;
justify-content: center;
align-items: center;
}
Ejemplo 2: posición central de CSS
/**************** 1º method to center all elements ********************/
body {
text-align: center;
}
/* If all of your elements have the property display equal to "inline",
"block" or "inline-block", then you can use the text-align: center in
the <body> tag */
tag_name {
display: inline; /* block or inline-block*/
}
/*...but if we have an element of type "block" with a width diferente
from the default (maximum width of the page), then this will no
longer work!*/
tag_name {
display: block;
width: 170px;
}
/**************** 2º method to center all elements ********************/
/* Another method, is to use the margins to center the element
horizontally and/or vertically */
tag_name {
display: block;
width: 100px;
margin: 0 auto 0 auto; /* top, right, bottom, left */
}
Ejemplo 3: cómo centrar la alineación del elemento html en ejemplos de CSS
#inner {
width: 50%;
margin: 0 auto;
}
# center text
.center {
text-align: center;
border: 3px solid green;
}
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)