Styling the Header
Style the header with CSS — navigation bar layout, logo, hover effects, and the hero banner section.
Styling the Header
Let's bring the header to life with CSS. We'll style the navigation bar, logo, hero section, and add smooth hover effects.
CSS Reset & Base Styles
/* === Reset === */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, sans-serif;
line-height: 1.6;
color: #444;
background: #f9f9f9;
}
a {
text-decoration: none;
color: inherit;
}
ul { list-style: none; }
img {
max-width: 100%;
height: auto;
}
/* === Container === */
.container {
max-width: 1100px;
margin: 0 auto;
padding: 0 20px;
}
Header Styles
#main-header {
background: #2c3e50;
color: #fff;
padding: 15px 0;
position: sticky;
top: 0;
z-index: 1000;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
}
.header-inner {
display: flex;
align-items: center;
justify-content: space-between;
}
.logo img {
width: 160px;
}
Navigation Styles
#main-nav ul {
display: flex;
align-items: center;
gap: 8px;
}
#main-nav ul li a {
color: #ccc;
font-size: 15px;
font-weight: 500;
padding: 8px 14px;
border-radius: 4px;
transition: all 0.3s ease;
}
#main-nav ul li a:hover,
#main-nav ul li a.current {
color: #fff;
background: rgba(255, 255, 255, 0.1);
}
Hero Section
#hero {
background: linear-gradient(rgba(44, 62, 80, 0.85), rgba(44, 62, 80, 0.85)),
url('../img/hero.jpg') no-repeat center center/cover;
color: #fff;
padding: 100px 0;
text-align: center;
}
.hero-content {
max-width: 650px;
margin: 0 auto;
}
.hero-content h1 {
font-size: 42px;
font-weight: 700;
margin-bottom: 20px;
line-height: 1.2;
}
.hero-content p {
font-size: 18px;
color: #ddd;
margin-bottom: 30px;
line-height: 1.7;
}
/* === Buttons === */
.btn {
display: inline-block;
padding: 12px 32px;
background: #3498db;
color: #fff;
font-size: 16px;
font-weight: 600;
border: none;
border-radius: 4px;
cursor: pointer;
transition: background 0.3s ease, transform 0.2s ease;
}
.btn:hover {
background: #2980b9;
transform: translateY(-2px);
}
CSS Techniques Explained
| Technique | What It Does |
|---|---|
position: sticky | Header sticks to top when scrolling |
display: flex + justify-content: space-between | Logo left, nav right |
linear-gradient over url() | Dark overlay on hero background image |
transition | Smooth hover effects on links and buttons |
box-shadow | Subtle depth under the sticky header |
rgba() | Semi-transparent colors for overlays and hover states |
Key Takeaways
- Start with a CSS reset and base styles for consistency
- Use Flexbox for header layout — logo on the left, nav on the right
position: stickywithtop: 0creates a modern fixed header- Combine
linear-gradientwithurl()for an image overlay in one line - Add
transitionto links and buttons for smooth hover effects - These same styles will carry into the WordPress theme's
style.css