Languages
[Edit]
EN

HTML - create grid using flexbox

3 points
Created by:
Majid-Hajibaba
972

In this article, we would like to show you how to create a grid using flexbox using JavaScript.

Grid created using flexbox and HTML.
Grid created using flexbox and HTML.

Practical example

In this example, we create a grid from div elements using CSS display: grid property. 

// ONLINE-RUNNER:browser;

<!DOCTYPE html>
<html>
<head>
  <style>

    .grid {
        display: flex; /*   <--- required   */
    }

    .column {
        flex: 1;       /*   <--- required   */
    }

    .row {
        margin: 2px;
        background: gold;
        text-align: center;
    }

  </style>
</head>
<body>
  <div class="grid">
    <div class="column">
      <div class="row">1.1</div>
      <div class="row">1.2</div>
      <div class="row">1.3</div>
    </div>
    <div class="column">
      <div class="row">2.1</div>
      <div class="row">2.2</div>
      <div class="row">3.3</div>
    </div>
    <div class="column">
      <div class="row">3.1</div>
      <div class="row">3.2</div>
      <div class="row">3.3</div>
    </div>
  </div>
</body>
</html>

 

See also

  1. JavaScript - dynamically create grid of divs using flexbox

References

  1. flex - CSS: Cascading Style Sheets | MDN

Alternative titles

  1. HTML - create grid using flexbox (default row direction)
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join