I’m trying to recreate a specific layout from my design mockup but can’t get the positioning right. I have four navigation boxes that need to be arranged in a 2x2 grid pattern. I’ve tried both flexbox and CSS grid but nothing seems to work properly.
Here’s what I have so far:
<!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="main.css">
<title>Travel Site</title>
</head>
<body>
<div class="wrapper">
<header class="header">
<div class="container">
<img src="logo.png" alt="Logo">
<nav class="navigation">
<a href="#" class="current">Home</a>
<a href="#">About</a>
<a href="#">Services</a>
<a href="#">Contact</a>
</nav>
<div class="auth-buttons">
<a href="#" class="login-btn">Login</a>
<a href="#" class="signup-btn">Sign Up</a>
</div>
</div>
</header>
<main class="main-content">
<div class="container">
<section class="hero-section">
<div class="hero-text">
<h1>Find Your Perfect Getaway</h1>
<p>Discover amazing destinations around the world</p>
<div class="divider"></div>
<div class="filter-grid">
<div class="filter-box">
<span>Location</span>
<img src="arrow.png" alt="">
</div>
<div class="filter-box">
<span>Category</span>
<img src="arrow.png" alt="">
</div>
<div class="filter-box">
<span>Rating</span>
<img src="arrow.png" alt="">
</div>
<div class="filter-box">
<span>Date</span>
<img src="arrow.png" alt="">
</div>
</div>
</div>
<div class="hero-image">
<img src="travel-image.jpg" alt="Travel">
</div>
</section>
</div>
</main>
</div>
</body>
</html>
And the CSS:
.filter-grid {
margin-top: 25px;
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-template-rows: repeat(2, 1fr);
gap: 15px;
max-width: 500px;
}
.filter-box {
width: 220px;
height: 50px;
border-radius: 8px;
border: 1px solid #ccc;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 15px;
}
The issue is with the filter-grid
class. I can’t seem to get these four boxes positioned correctly in a 2x2 layout. Any suggestions on what I might be doing wrong?