html Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Semantic Grid Layout Modernization</title>
<style>
/* Reset and base styles for modern layout */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: system-ui, -apple-system, sans-serif;
line-height: 1.6;
color: #333;
}
/* Overall page layout using CSS Grid (replaces floats/flex stacking) */
.page-grid {
display: grid;
grid-template:
"header" auto
"hero" auto
"cards" 1fr
"footer" auto
/ 1fr;
min-height: 100vh;
gap: 2rem;
padding: 2rem;
max-width: 1200px;
margin: 0 auto;
}
/* Semantic header with nav */
header {
grid-area: header;
display: flex;
justify-content: space-between;
align-items: center;
padding: 1rem 0;
border-bottom: 2px solid #eee;
}
nav ul {
display: flex;
list-style: none;
gap: 2rem;
}
nav a {
text-decoration: none;
color: #333;
font-weight: 500;
}
/* Hero section */
.hero {
grid-area: hero;
text-align: center;
padding: 4rem 2rem;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border-radius: 1rem;
}
.hero h1 {
font-size: clamp(2rem, 5vw, 4rem);
margin-bottom: 1rem;
}
/* Cards grid: Equal heights via CSS Grid (replaces float/flex card layouts) */
.cards-grid {
grid-area: cards;
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 2rem;
/* Equal height rows by default with stretch alignment */
align-items: stretch;
}
.card {
background: white;
border-radius: 1rem;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
overflow: hidden;
transition: transform 0.3s ease, box-shadow 0.3s ease;
display: grid;
grid-template-rows: auto 1fr auto; /* Logical internal structure: header/content/footer */
gap: 1.5rem;
padding: 2rem;
}
.card:hover {
transform: translateY(-4px);
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.15);
}
.card-header img {
width: 100%;
height: 200px;
object-fit: cover;
}
.card-content h3 {
margin-bottom: 0.5rem;
color: #333;
}
.card-content p {
color: #666;
}
.card-footer {
display: flex;
justify-content: space-between;
align-items: center;
font-weight: 600;
color: #667eea;
}
/* Footer */
footer {
grid-area: footer;
text-align: center;
padding: 2rem;
background: #f8f9fa;
border-radius: 1rem;
}
/* Responsive: Mobile-first grid adjustments */
@media (max-width: 768px) {
.page-grid {
padding: 1rem;
gap: 1rem;
}
nav ul {
gap: 1rem;
}
.cards-grid {
grid-template-columns: 1fr;
gap: 1.5rem;
}
}
</style>
</head>
<body>
<!-- Semantic, logical source order: Matches visual top-to-bottom flow -->
<div class="page-grid">
<!-- Header: Branding + Navigation -->
<header>
<h2>Logo</h2>
<nav>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#services">Services</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</nav>
</header>
<!-- Hero: Full-width call-to-action -->
<section class="hero" aria-labelledby="hero-heading">
<h1 id="hero-heading">Welcome to Modern Grid Layouts</h1>
<p>Experience semantic, equal-height cards powered by CSS Grid—no floats or flex hacks needed.</p>
</section>
<!-- Main content: Grid of equal-height cards -->
<main class="cards-grid" role="main">
<article class="card">
<div class="card-header">
<img src="https://via.placeholder.com/400x200/667eea/ffffff?text=Card+1" alt="Feature 1 illustration">
</div>
<div class="card-content">
<h3>Feature One</h3>
<p>Detailed description of the first feature, with varying content lengths to demonstrate equal heights via Grid.</p>
</div>
<div class="card-footer">
<span>Learn More</span>
<span>→</span>
</div>
</article>
<article class="card">
<div class="card-header">
<img src="https://via.placeholder.com/400x200/764ba2/ffffff?text=Card+2" alt="Feature 2 illustration">
</div>
<div class="card-content">
<h3>Feature Two</h3>
<p>Shorter content here, but Grid ensures perfect alignment and equal heights across all cards.</p>
</div>
<div class="card-footer">
<span>Explore</span>
<span>→</span>
</div>
</article>
<article class="card">
<div class="card-header">
<img src="https://via.placeholder.com/400x200/4ecdc4/ffffff?text=Card+3" alt="Feature 3 illustration">
</div>
<div class="card-content">
<h3>Feature Three</h3>
<p>This card has more text to showcase how CSS Grid automatically balances heights without JavaScript or flex hacks. Semantic structure maintained.</p>
<ul>
<li>Equal heights</li>
<li>Logical flow</li>
<li>Responsive</li>
</ul>
</div>
<div class="card-footer">
<span>Get Started</span>
<span>→</span>
</div>
</article>
</main>
<!-- Footer -->
<footer>
<p>© 2023 Modern Layouts. Built with semantic HTML & CSS Grid.</p>
</footer>
</div>
</body>
</html>
Copy-paste into a file and open in browser to test! Resize to see equal heights and responsiveness.