Lab 0: Warm up and getting Started:
Lab Instruction Workflow: Responsive Web Page Layout with Flexbox
Objective:
Learn to create a flexible and responsive web page layout using HTML and CSS Flexbox.
Part 1: Setup
Task 1: Create a new HTML file named flexbox-layout.html.
Task 2: Create a new CSS file named flexbox-style.css.
Part 2: HTML Structure
flexbox-layout.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flexbox Layout</title>
<link rel="stylesheet" href="flexbox-style.css">
</head>
<body>
<header class="main-header">Header</header>
<nav class="main-nav">Navigation</nav>
<section class="main-content">Content</section>
<aside class="sidebar">Sidebar</aside>
<footer class="main-footer">Footer</footer>
</body>
</html>
Task 3: Link your CSS file within the HTML head section.
Task 4: Create the basic structure of a web page with header, navigation, content, sidebar, and footer.
Part 3: CSS Styling with Flexbox
flexbox-style.css:
body {
margin: 0;
font-family: Arial, sans-serif;
}
.main-header, .main-nav, .main-footer {
text-align: center;
padding: 1rem;
background-color: #333;
color: white;
}
.main-content, .sidebar {
padding: 1rem;
}
/* Flexbox container */
body {
display: flex;
flex-direction: column;
min-height: 100vh;
}
.main-content {
flex: 1;
}
/* Responsive design */
@media (min-width: 768px) {
body {
flex-direction: row;
}
.main-nav, .main-content, .sidebar {
flex: 1;
}
.sidebar {
order: -1; /* Move sidebar to the left side */
}
}
Task 5: Add CSS to style each section of the page.
Use Flexbox to create a column layout for mobile and switch to a row layout for wider screens.
##############
To complete Task 5, we will add additional CSS to style each section of the page and use Flexbox to create a column layout for mobile devices and a row layout for wider screens.
We will utilize Flexbox properties to make the layout responsive, with a column structure on small screens and a row structure on larger screens (above 768px width).
Here’s the updated CSS that you will add to the flexbox-style.css file:
CSS: flexbox-style.css
/* Base styling for body and layout structure */
body {
margin: 0;
font-family: Arial, sans-serif;
display: flex;
flex-direction: column; /* Stack sections vertically by default */
min-height: 100vh; /* Full height of the viewport */
}
/* Header, Navigation, Footer styles */
.main-header, .main-nav, .main-footer {
text-align: center;
padding: 1rem;
background-color: #333;
color: white;
}
/* Main content and sidebar */
.main-content, .sidebar {
padding: 1rem;
}
/* Flexbox: allow main content to grow and take up space */
.main-content {
flex: 1;
background-color: #f4f4f4; /* Light background for content */
}
.sidebar {
background-color: #eaeaea; /* Slightly different color for sidebar */
padding: 1rem;
}
/* Footer styling */
.main-footer {
background-color: #444; /* Darker footer background */
color: white;
padding: 1rem;
text-align: center;
}
/* Responsive design for wider screens */
@media (min-width: 768px) {
/* Switch to a row layout when screen width is 768px or more */
body {
flex-direction: row;
}
/* Header stays at the top (spans entire width) */
.main-header {
width: 100%;
}
/* Navigation, content, and sidebar aligned side by side */
.main-nav, .main-content, .sidebar {
flex: 1;
padding: 1rem;
}
/* Sidebar to the left on wider screens */
.sidebar {
order: -1; /* Move sidebar to the left of content */
flex-basis: 20%; /* Sidebar takes up 20% of space */