Open In App

Foundation CSS XY Grid Build Semantically

Foundation CSS XY Grid utilizes Flexbox and CSS Grid under the hood providing a semantic grid structure that supports both row-based and column-based layouts. It enables developers to create complex grid patterns while maintaining semantic HTML markup improving accessibility and SEO.

Foundation CSS XY Grid Classes

Syntax

<div class="container">
<div class="row">
<div class="col small-6 medium-4 large-3">Column 1</div>
<div class="col small-6 medium-4 large-3">Column 2</div>
<div class="col small-12 medium-4 large-6">Column 3</div>
</div>
</div>

In the above syntax, we have a container with three columns. The small-6, medium-4 and large-3 classes define how many columns each element should occupy on different screen sizes.



Example 1: In this example, we will create a basic 3-Column Grid structure.

 






<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content=
        "width=device-width, initial-scale=1.0">
    <link rel="stylesheet" 
        href="path/to/foundation.min.css">
          
    <style>
        .box {
            padding: 20px;
            text-align: center;
            margin-bottom: 10px;
        }
  
        .red-box {
            background-color: yellow;
        }
  
        .green-box {
            background-color: rgb(0, 128, 255);
        }
  
        .blue-box {
            background-color: rgba(255, 0, 0, 0.5);
        }
    </style>
</head>
  
<body>
    <div class="grid-container">
        <div class="grid-x grid-margin-x">
            <div class="cell small-12 medium-4">
                <div class="box red-box">Column 01</div>
            </div>
            <div class="cell small-12 medium-4">
                <div class="box green-box">Column 02</div>
            </div>
            <div class="cell small-12 medium-4">
                <div class="box blue-box">Column 03</div>
            </div>
        </div>
    </div>
    <script src="path/to/foundation.min.js"></script>
</body>
  
</html>

Output:

Example 2: In this example, we will create a 3 Cell grid structure.




<!DOCTYPE html>
<html lang="en">
  
<head>
    <link rel="stylesheet" href=
    <script src=
    </script>
</head>
  
<body style="margin-inline: 10rem">
    <h1 style="color: green">
        Welcome to GeeksforGeeks
    </h1>
    <h3 style="color: blue">
        -----Foundation CSS XY Grids----
    </h3>
    <div class="grid-x grid-padding-x 
        small-up-2 medium-up-4 large-up-6">
        <div class="cell" style="background-color: red">
            Geeks!
        </div>
        <div class="cell" 
            style="background-color: rgb(147, 180, 151)">
            Geeks!
        </div>
        <div class="cell" 
            style="background-color: rgb(0, 355, 191)">
            Geeks!
        </div>
    </div>
</body>
  
</html>

Output:

Reference: https://get.foundation/sites/docs/xy-grid.html#building-semantically


Article Tags :