Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

135
Vistas
how to position items inside css grid?

I'm learning the CSS grid and trying to position the items inside the grid?

can get and see data from javascript:

const profileImg = document.createElement('img');
var profilePhotoUrl = post.user.get("photo").url();
profileImg.src = profilePhotoUrl;
profileImg.className = "profile";

const username = document.createElement('username');
username.className = "user";
username.innerText = post.name;
const content = document.querySelector('.content'); 
content.append(profileImg, username);

putting a full CSS here:

body, html {
    margin: 0;
    height: 100%;
    font-family: Arial, Helvetica, sans-serif;
}
body {
    display: grid;
    margin: 0;
    grid-template-columns: 20% auto;
    grid-template-rows: 60px auto 100px;
    grid-template-areas: 
        "header header"
        "sidebar content"
        "sidebar footer";
}
header {
    position: sticky;
    grid-area: header;
    background-color: rgb(0, 0, 0);
   
}
aside {
    grid-area: sidebar;
    background-color: lightsteelblue;
}
.content {
    display: inline-flex;
    align-items: center;
}

footer {
    grid-area: footer;
    background-color: rgb(121, 121, 121);
    padding: 10px;
}

.user { 
    grid-area: user; 
    font-size: 10pt;
    
 }

.profile {
    grid-area: profile;
 }

HTML:

<html>
    <head>
        <meta charset="utf-8" />
        <link rel="stylesheet" href="style.css">
    
    </head>
    <body>
        <aside>
            <ul>
                <li><a href="#">home</a></li>        
                <li><a href="#">about</a></li>   
                <li><a href="#">service</a></li>   
                <li><a href="#">contact</a></li>   
            </ul>
        </aside>

        <header>
            <h1>Diky</h1>
        </header>
        <div class="content">
            
        </div>
        <footer>
            <p>this is my footer</p>
        </footer>
        <script src="app.js"></script>
    </body>
    </html>
      

And it looks like this. How can I position them vertically? How can I position elements that are created from javascript?

(profile username) <--like this
(profile username)
(profile username) 

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Firstly, I recommend not using flexbox with grid, for the same purpose, as it ruins ur understanding of grid. ANyways here's the code

<!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">
    <title>Document</title>
    <style>
  /*    Main grid container styling */

  .grid-container{
display: grid;
/* This is used for the position into 3 columns */
grid-template-columns: 1fr 1fr 1fr;
/* For the margin between the three items */
grid-gap: 1rem;
/* For centering of items */
justify-content: center;
align-items: center;
  }


  /* For styling of grid items */

.grid-container-items{
    height: 200px;
    width: 200px;
    background: red;
}
    </style>
</head>
<body>
<div class="grid-container">
    <div class="grid-container-items"></div>
    <div class="grid-container-items"></div>
    <div class="grid-container-items"></div>
</div>
</body>
</html>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda