Hola a todos!
En esta ocasión explicare como pueden centrar un elemento de un div 👩💻
- Tenemos que crear un div con un identificador en mi caso lo llame class = container
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Document</title>
</head>
<body>
<div id="container">
</div>
</body>
</html>
- Luego creamos el elemento, en mi caso cree un <p></p>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Document</title>
</head>
<body>
<div id="container">
<p>centrame</p>
</div>
</body>
</html>
- Continuamos con la creación del .css. En el file agregamos los estilos propios del #containe.
#container{
background-color:red;
width:100px;
height:100px;
}
4 . Finalmente, vamos a centrar el elemento usando Flex
#container{
background-color:red;
width:100px;
height:100px;
display:flex;
justify-content:center;
align-items:center;
}
Resultado

Curso de Frontend Developer
0 Comentarios
para escribir tu comentario