CSS Styling
CSS (Cascading Style Sheets) controls how your HTML looks — colors, layouts, fonts, spacing, and animations. Let's explore the key concepts with practical examples.
1. CSS Reset & Box Model
Browsers apply default styles that differ from one another. A CSS reset removes these inconsistencies. The box-sizing: border-box property ensures padding and border are included in an element's total width.
* { margin: 0; padding: 0; box-sizing: border-box; } body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; line-height: 1.75; color: #e8e0d5; background-color: #1a1612; }
*— universal selector, targets every elementbox-sizing: border-box— prevents overflow issues by including padding in widthfont-family— system font stack for cross-platform consistencyline-height— controls spacing between lines of text
2. Colors & Typography
CSS offers multiple ways to define colors: named colors, hex codes, rgb(), and hsl(). Typography properties control font size, weight, spacing, and decoration.
h1 { font-size: 62px; font-weight: 700; letter-spacing: -1.5px; color: #f5e8d3; } p { font-size: 18px; color: rgba(232, 224, 213, 0.92); max-width: 640px; } a { text-decoration: none; color: inherit; transition: color 0.3s ease; } a:hover { color: #d4b48c; }
3. Flexbox Layout
Flexbox is the go-to layout model for one-dimensional alignment. Use display: flex to create a flex container, then control alignment and spacing with properties like justify-content and gap.
.nav-container { max-width: 1280px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; padding: 0 40px; } nav ul { list-style: none; display: flex; gap: 40px; align-items: center; } .hero-buttons { display: flex; gap: 24px; flex-wrap: wrap; }
justify-content: space-between pushes items to opposite edges. Combined with align-items: center, it perfectly aligns a logo on the left and nav links on the right.
4. Sticky Header & Backdrop Blur
A sticky header remains visible while scrolling. The backdrop-filter property creates a frosted glass (glassmorphism) effect, a popular modern design trend.
header { background-color: rgba(26, 22, 18, 0.95); backdrop-filter: blur(8px); padding: 22px 0; position: sticky; top: 0; z-index: 100; border-bottom: 1px solid #3c2f2f; }
position: sticky— sticks the element when scrolling past itbackdrop-filter: blur()— blurs content behind the elementz-index: 100— ensures the header stays on top of all contentrgba()— adds transparency for the glass effect
5. Background Images & Overlays
Use background-image with cover to create full-width hero banners. A pseudo-element (::before) overlay adds a dark tint so text remains readable.
.hero { position: relative; height: 720px; background-image: url('../img/hero.jpg'); background-size: cover; background-position: center; display: flex; align-items: center; } .hero::before { content: ''; position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: linear-gradient( rgba(26,22,18,0.65), rgba(26,22,18,0.75) ); z-index: 1; } .hero-content { position: relative; z-index: 2; }
z-index: 1 while the content has z-index: 2 so it appears above the dark layer. This technique works with any background image.
6. Button Styles
Two common button patterns: a solid CTA (Call to Action) button and a "ghost" button with a transparent background and visible border. Hover effects add polish.
.btn-cta { background-color: #d4b48c; color: #1a1612; padding: 18px 44px; border: none; border-radius: 50px; font-weight: 600; text-decoration: none; transition: all 0.4s ease; } .btn-cta:hover { background-color: #e8d0a8; transform: translateY(-3px); } .btn-ghost { background-color: transparent; color: #e8e0d5; padding: 18px 44px; border: 2px solid #e8e0d5; border-radius: 50px; transition: all 0.4s ease; } .btn-ghost:hover { background-color: #e8e0d5; color: #1a1612; }
7. CSS Grid — Card Layouts
CSS Grid is ideal for two-dimensional layouts. The auto-fit keyword with minmax() creates automatically responsive grids without media queries.
.service-grid { display: grid; grid-template-columns: repeat( auto-fit, minmax(340px, 1fr) ); gap: 40px; } .service-card { background: #24201b; border-radius: 20px; overflow: hidden; transition: transform 0.4s, box-shadow 0.4s; display: flex; flex-direction: column; } .service-card:hover { transform: translateY(-12px); box-shadow: 0 25px 50px rgba(0, 0, 0, 0.35); }
repeat(auto-fit, minmax(340px, 1fr)) automatically adjusts the number of columns based on available space — no breakpoints needed for the grid itself.
8. Transitions & Hover Effects
The transition property adds smooth animated changes when CSS values update. Combine it with :hover for interactive, polished UI elements.
.tab-btn { background-color: #1a1612; color: #e8e0d5; border: 2px solid #3c2f2f; padding: 16px 32px; border-radius: 50px; cursor: pointer; transition: all 0.4s ease; } .tab-btn:hover { background-color: #2a211b; border-color: #d4b48c; } .tab-btn.active { background-color: #d4b48c; color: #1a1612; font-weight: 600; } .gallery-image { width: 100%; object-fit: cover; transition: opacity 0.5s ease; }
9. Responsive Design — Media Queries
Media queries apply styles only when certain conditions are met (like screen width). This lets you adapt layouts for phones, tablets, and desktops.
@media (max-width: 768px) { .service-grid { grid-template-columns: 1fr; } .hero { height: 620px; } .hero h1 { font-size: 48px; } .nav-container { padding: 0 20px; } }
@media (max-width: 768px) targets screens 768px wide or narrower. At this breakpoint, the grid collapses to a single column and font sizes are reduced for mobile readability.