Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

161
Views
How to get my grid stay inside of its container?

I am trying to fit my grid of 16x16 or 64x64 (the size shound't matter) inside of my grid. I was thinking of using flexbox, but im not sure how to go about implementing that. I'd like for my grid to shrink and expand according to the size of the container, rather than being popped outside of the container.

```<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">
    <script src="./index.js" defer></script>
    <title>Document</title>
</head>
<body>
    <div class="flex-container">
        <div id="container"></div>
    </div>


</body>
</html>```


CSS:

```:root {
    --grid-cols: 1;
    --grid-rows: 1;
  }
  

#container {
    background-color: white;
    width: 50%;
    height: 100%;
}

.flex-container {
    background-color: coral;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 70%;
}


  #container {
    display: grid;
    grid-gap: 1em;
    grid-template-rows: repeat(var(--grid-rows), 1fr);
    grid-template-columns: repeat(var(--grid-cols), 1fr);
  }
  
  .grid-item {
    padding: 1em;
    text-align: center;
  }

  .grid-item:hover {
      background-color: beige;
  }```

Javascript:
```const container = document.getElementById("container");

function makeRows(rows, cols) {
  container.style.setProperty('--grid-rows', rows);
  container.style.setProperty('--grid-cols', cols);
  for (c = 0; c < (rows * cols); c++) {
    let cell = document.createElement("div");
    container.appendChild(cell).className = "grid-item";
  };
};

makeRows(16, 16);```
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try this change size according to your need

grid-template-columns: repeat(auto-fill,minmax(200px,1fr));
  grid-auto-rows: minmax(100px, auto);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!