Certainly! To create a similar header using HTML and CSS, we'll break down the structure and functionality step by step based on the provided code snippet. Below is a simplified example. Note that for a complete implementation, additional details such as JavaScript for dropdown functionality and responsiveness would be necessary.
HTML Structure
Here’s a basic implementation of a header similar to what you provided:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>California Olive Ranch Header</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<!-- Header Structure -->
<div class="detachable-header">
<header class="max-w-full">
<div role="navigation" class="columns max-w-wide">
<div class="left">
<a href="/" tabindex="1" class="logo-link">
<img src="logo.svg" alt="California Olive Ranch" class="logo">
</a>
</div>
<div class="center">
<div class="desktop-nav">
<div class="desktop-nav-item">
<div class="link-with-dropdown">
<div role="button" tabindex="0" aria-label="Shop" class="accessibility-btn dropdown-trigger" aria-expanded="false">
<div class="title">Shop</div>
<div class="icon-small-caret"></div>
</div>
</div>
</div>
<div class="desktop-nav-item">
<a href="/california-olive-ranch" class="standard-link" aria-current="page">
<div class="title">California Olive Ranch</div>
</a>
</div>
<div class="desktop-nav-item">
<a href="/lucini" class="standard-link">
<div class="title">Lucini</div>
</a>
</div>
<div class="desktop-nav-item">
<a href="/our-story" class="standard-link">
<div class="title">Our Story</div>
</a>
</div>
<div class="desktop-nav-item">
<a href="/store-locator" class="standard-link">
<div class="title">Store Locator</div>
</a>
</div>
</div>
</div>
<div class="right">
<a href="/collections/all" class="btn">Shop All</a>
<div class="search-trap">
<div role="button" tabindex="0" aria-label="Open search menu" class="accessibility-btn">
<div class="icon icon-search"></div>
</div>
</div>
<a href="/account/login" aria-label="account" class="icon icon-account">Account</a>
<div role="button" tabindex="0" aria-label="cart" class="accessibility-btn" id="cart-icon-button">
<div class="icon cart-with-oil">Cart (0)</div>
</div>
</div>
</div>
</header>
</div>
<script src="script.js"></script>
</body>
</html>
CSS Styling
Here's a simple CSS file (styles.css) to style the header:
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: Arial, sans-serif;
}
.detachable-header {
position: sticky;
top: 0;
transition: all 0.3s ease;
background-color: white;
height: 80px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
z-index: 10;
}
.max-w-full {
width: 100%;
}
.columns {
display: flex;
justify-content: space-between;
align-items: center;
max-width: 1200px;
margin: 0 auto;
padding: 0 20px;
}
.left, .center, .right {
display: flex;
align-items: center;
}
.logo {
height: 50px; /* Adjust based on your logo */
}
.desktop-nav {
display: flex;
gap: 20px;
}
.desktop-nav-item {
position: relative;
}
.link-with-dropdown:hover .dropdown {
display: block; /* Show dropdown on hover */
}
.dropdown {
display: none; /* Initially hidden */
position: absolute;
background: white;
border: 1px solid #ccc;
}
.btn {
background-color: darkgreen;
color: white;
padding: 10px 15px;
border-radius: 20px;
text-decoration: none;
}
.accessibility-btn {
cursor: pointer;
margin-left: 15px;
}
.icon {
width: 24px; /* Adjust based on your icon */
height: 24px;
display: inline-block;
margin-left: 15px;
}
.cart-with-oil {
color: darkgreen; /* Example icon color */
}
JavaScript (Optional)
If you want dropdown functionality or interactivity, you might add JavaScript. Here’s a basic example:
// script.js
document.querySelectorAll('.dropdown-trigger').forEach(trigger => {
trigger.addEventListener('click', () => {
const expanded = trigger.getAttribute('aria-expanded') === 'true' || false;
// Toggle ARIA attribute and dropdown display
trigger.setAttribute('aria-expanded', !expanded);
// Update dropdown visibility (assumes dropdown is a sibling)
const dropdown = trigger.parentElement.querySelector('.dropdown');
if (dropdown) {
dropdown.style.display = expanded ? 'none' : 'block';
}
});
});
Summary
This code provides a basic statically designed header that aligns with functional requirements found in modern web applications. The setup includes:
- A sticky header that remains at the top during scrolling.
- Logo on the left.
- Navigation items in the center.
- Utility buttons (e.g., shopping cart, search) on the right.
Next Steps
- Testing and Responsiveness: Ensure to test across devices and resolutions.
- Styling Improvements: Adjust the styles to better fit the overall brand and website aesthetics.
- Dropdown Functionality: Enhance and fine-tune dropdown menus as needed.
- Accessibility: Verify that all interactive elements are keyboard navigable and use appropriate ARIA roles.
By following these guidelines, you can create a similarly functional and engaging header for your website!