Member-only story

Difference between grid and flexbox

Pravin M
3 min readFeb 20, 2024

--

Difference between grid and flexbox
Difference between grid and flexbox

Source:- Difference between grid and flexbox

For more questions and answers visit our website at Frontend Interview Questions

CSS Grid and CSS Flexbox are both powerful layout systems in CSS that provide different approaches to creating responsive and flexible layouts. Here’s a detailed comparison of CSS Grid and CSS Flexbox, along with examples:

CSS Grid:

CSS Grid is a two-dimensional layout system that allows you to create complex grid-based layouts with rows and columns. It provides precise control over the placement and alignment of elements within the grid.

Example:


<div class="grid-container">
<div class="item">Item 1</div>
<div class="item">Item 2</div>
<div class="item">Item 3</div>
</div>

.grid-container {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-gap: 10px;
}

.item {
background-color: #ddd;
padding: 20px;
}

In this example, we create a grid container with three columns using the `grid-template-columns` property. The `1fr` value represents a fraction of the available space, so each column will have an equal width. We also set a gap of 10 pixels between grid items using the `grid-gap` property. The grid items inside the container will be placed automatically in the…

--

--

Pravin M
Pravin M

Written by Pravin M

I am a frontend developer with 10+ years of experience Blog :- https://www.frontendinterviewquestions.com

No responses yet