Project Setup
Project Structure
We’ll use a minimal structrue with root HTML, a css folder for styles, and an images folder for assets like sprite sheets and banner images.
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./css/normalize.css">
<link rel="stylesheet" href="./css/index.css">
<title>Travel App - Explore Anywhere</title>
</head>
<body>
<header class="header-bar">
<div class="search-field">Search: Destinations, Hotels, Attractions...</div>
<a href="#" class="profile-link">Profile</a>
</header>
<section class="hero-banner">
<img src="./upload/hero-banner.jpg" alt="Featured Travel Destination">
</section>
</body>
</html>
Base CSS (index.css)
body {
max-width: 540px;
min-width: 320px;
margin: 0 auto;
font: normal 14px/1.5 "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
color: #333;
background-color: #f5f5f5;
overflow-x: hidden;
-webkit-tap-highlight-color: transparent;
box-sizing: border-box;
}
* {
box-sizing: inherit;
}
Fixed Header with Flexbox
Create a responsive, fixed header that remains centerde across all device widths. Use flexbox to allocate space between the search field and profile link.
.header-bar {
display: flex;
position: fixed;
top: 0;
left: 50%;
transform: translateX(-50%);
width: 100%;
min-width: 320px;
max-width: 540px;
height: 44px;
background-color: #f8f8f8;
border-top: 1px solid #e0e0e0;
border-bottom: 1px solid #e0e0e0;
z-index: 100;
}
.search-field {
flex: 1;
position: relative;
height: 28px;
line-height: 26px;
border: 1px solid #ddd;
font-size: 12px;
color: #666;
margin: 8px 12px;
padding-left: 28px;
border-radius: 6px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
background-color: #fff;
}
.profile-link {
width: 44px;
height: 44px;
font-size: 12px;
text-align: center;
color: #2da4e0;
text-decoration: none;
}
Profile Link Styling
Add an icon using a 2x resolution sprite sheet for sharp display on high-DPI screens. Position the icon above the profile text.
.profile-link::before {
content: "";
display: block;
width: 22px;
height: 22px;
background: url(../images/icons-sprite.png) no-repeat -60px -195px;
background-size: 104px auto;
margin: 4px auto 2px;
}
Search Field Icon
Insert a magnifying glass icon inside the search field using absolute positioning and the same sprite sheet.
.search-field::before {
content: "";
position: absolute;
top: 4px;
left: 6px;
width: 16px;
height: 16px;
background: url(../images/icons-sprite.png) no-repeat -60px -280px;
background-size: 104px auto;
}
Hero Banner
Adjust padding to account for the fixed header, ensuring the banner is visible below it.
.hero-banner {
padding-top: 44px;
}
.hero-banner img {
width: 100%;
height: auto;
display: block;
}