Alaa Amer Articles

We offer a comprehensive collection of essential educational articles in web development to turn your ideas into digital reality

CSS Grid: Complete Guide to Advanced Grid Layout and Two-Dimensional Control

CSS 2026-01-01 Alaa Amer

CSS Grid: Complete Guide to Advanced Grid Layout and Two-Dimensional Control

Professional Guide by Alaa Amer – Expert Web Developer & Designer

CSS Grid is the most powerful layout system for controlling rows and columns. Learn to create complex and responsive layouts with high precision.

2️⃣ Defining Columns and Rows

.grid-definition {
  display: grid;

  /* Column definition */
  grid-template-columns:
    200px /* fixed column */
    1fr /* flexible column */
    minmax(100px, 200px) /* column with min and max */
    auto; /* content-based */

  /* Row definition */
  grid-template-rows:
    60px /* fixed header */
    1fr /* flexible content */
    50px; /* fixed footer */

  /* Definition using line names */
  grid-template-columns:
    [sidebar-start] 250px
    [sidebar-end main-start] 1fr
    [main-end aside-start] 200px
    [aside-end];
}

/* Advanced examples */
.responsive-columns {
  display: grid;

  /* Responsive grid */
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
  padding: 20px;
}

.magazine-layout {
  display: grid;
  grid-template-columns:
    1fr /* main content */
    300px /* sidebar */
    200px; /* ads */
  grid-template-rows:
    80px /* header */
    1fr /* content */
    60px; /* footer */
  gap: 20px;
  min-height: 100vh;
}

4️⃣ Grid Areas - Named Areas

.layout-areas {
  display: grid;
  grid-template-areas:
    "header header header"
    "sidebar main aside"
    "footer footer footer";
  grid-template-columns: 200px 1fr 150px;
  grid-template-rows: 80px 1fr 60px;
  gap: 20px;
  min-height: 100vh;
}

/* Assigning elements to areas */
.header {
  grid-area: header;
}
.sidebar {
  grid-area: sidebar;
}
.main {
  grid-area: main;
}
.aside {
  grid-area: aside;
}
.footer {
  grid-area: footer;
}

/* Responsive layout by changing areas */
@media (max-width: 768px) {
  .layout-areas {
    grid-template-areas:
      "header"
      "main"
      "sidebar"
      "aside"
      "footer";
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto auto auto;
  }
}

/* Complex magazine layout */
.magazine-areas {
  display: grid;
  grid-template-areas:
    "header header header header"
    "hero hero sidebar-1 sidebar-1"
    "article-1 article-2 sidebar-1 sidebar-1"
    "article-3 article-3 sidebar-2 ads"
    "footer footer footer footer";
  grid-template-columns: 1fr 1fr 200px 150px;
  gap: 20px;
}

6️⃣ Advanced Responsive Grid

/* Fully responsive grid */
.responsive-advanced-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
  padding: 20px;
}

/* Different layouts for screens */
.adaptive-layout {
  display: grid;
  gap: 20px;

  /* Large screens */
  grid-template-columns: 250px 1fr 200px;
  grid-template-areas:
    "sidebar main aside"
    "sidebar main aside";
}

@media (max-width: 1024px) {
  .adaptive-layout {
    /* Medium screens */
    grid-template-columns: 200px 1fr;
    grid-template-areas:
      "sidebar main"
      "aside aside";
  }
}

@media (max-width: 768px) {
  .adaptive-layout {
    /* Small screens */
    grid-template-columns: 1fr;
    grid-template-areas:
      "main"
      "sidebar"
      "aside";
  }
}

/* Grid with different density */
.density-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 15px;
}

.featured-item {
  grid-column: span 6; /* half width */
}

.regular-item {
  grid-column: span 4; /* third width */
}

.small-item {
  grid-column: span 3; /* quarter width */
}

@media (max-width: 768px) {
  .featured-item,
  .regular-item,
  .small-item {
    grid-column: span 12; /* full width on mobile */
  }
}

7️⃣ Practical Project: Advanced Dashboard

The HTML and CSS remain structurally the same as the Arabic version, with appropriate text direction and language adjustments for English.

Summary

In this lesson we learned:

CSS Grid fundamentalsAdvanced column and row definitionItem placement and named areasGrid alignmentResponsive design with GridAdvanced dashboard project

In the next lesson we'll study Position and Positioning for precise element positioning control.

📩 Need help with CSS Grid?

CSS Grid Layout Responsive Advanced Frontend Web Design
Article Category
CSS

CSS Grid: Complete Guide to Advanced Grid Layout and Two-Dimensional Control

Master CSS Grid - grid layouts, areas, alignment, and precise control over rows and columns. Practical guide for complex layouts.

CSS Grid: Complete Guide to Advanced Grid Layout and Two-Dimensional Control
01

Consultation & Communication

Direct communication via WhatsApp or phone to understand your project needs precisely.

02

Planning & Scheduling

Creating clear work plan with specific timeline for each project phase.

03

Development & Coding

Building projects with latest technologies ensuring high performance and security.

04

Testing & Delivery

Comprehensive testing and thorough review before final project delivery.

Alaa Amer
Alaa Amer

Professional web developer with over 10 years of experience in building innovative digital solutions.

Need This Service?

Contact me now for a free consultation and quote

WhatsApp Your satisfaction is our ultimate goal

What We Offer

  • Website Maintenance & Updates

    Keep your website secure updated optimized

  • API Integration

    Connect your systems with powerful APIs

  • Database Design & Optimization

    Faster queries cleaner structure fewer issues

  • Website Security Hardening

    Protect your site from cyber threats

  • Automation & Scripts

    Automate repetitive tasks and save time

Have Questions?

Call Us Now

00201014714795