Practice and reinforce the concepts from Lesson 5
<div>
elements for structured layoutsTime: 2 minutes
:warning: IMPORTANT: Before You Start DO NOT DELETE the existing files in the template:
- Package files
- Any other files you didn't create
ONLY EDIT the necessary files (index.html and style.css)
In this activity, you will practice using HTML <div>
elements to create structured layouts. You'll build a "My Dinner" webpage featuring nested divisions, CSS styling, and properly spaced elements.
Time: 2 minutes
Study the final result to understand what you're building:
tip Take a moment to identify the different divisions in the output:
Time: 5 minutes
index.html
page in a new windowindex.html
file, change the title of the document to My Dinnerstyle.css
file and link it to the index.html
filetip Finding Good Images
Time: 5 minutes
In your index.html
file, under the <body>
:
<div>
with an id
named title<div>
, add:
<h1>
tag with the content: My Dinner<p>
tag with the content: These are the 3 types of food I eat during my dinnerIn your style.css
file:
text-align: center;
background-color: aqua;
tip ID Selector Reminder Remember that ID selectors use the # symbol. For example:
#title {
/* your styles here */
}
Time: 7 minutes
In your index.html
file, after the title div:
<div>
with a class named dining-table<div>
, create three child divisions:
<div class="red-plate"></div>
<div class="yellow-plate"></div>
<div class="green-plate"></div>
In your style.css
file:
Class | CSS Properties |
---|---|
.dining-table |
height: 300px; width: 500px; background-color: sandybrown; |
.red-plate |
height: 60px; width: 60px; background-color: red; |
.yellow-plate |
height: 60px; width: 60px; background-color: yellow; |
.green-plate |
height: 60px; width: 60px; background-color: green; |
tip Nesting Structure Your HTML structure should look like this:
<div class="dining-table">
<div class="red-plate"></div>
<div class="yellow-plate"></div>
<div class="green-plate"></div>
</div>
Time: 5 minutes
In your index.html
file:
<div class="red-plate">
, add an <img>
tag with your first food image<div class="yellow-plate">
, add an <img>
tag with your second food image<div class="green-plate">
, add an <img>
tag with your third food imageIn your style.css
file:
<img>
tags:
height: 60px;
width: 60px;
tip Image Paths If your images are in the assets folder, your img tags should look like:
<img src="assets/your-food-image.png" alt="Food description">
Always include alt text for accessibility!
Time: 8 minutes
In your style.css
file:
Add padding to the title division:
#title {
padding: 20px;
/* keep your existing styles */
}
Center the dining table on the page:
.dining-table {
margin: 50px auto;
padding: 30px;
/* keep your existing styles */
}
Position the plates using display and margin:
.red-plate, .yellow-plate, .green-plate {
display: inline-block;
margin: 20px;
/* keep your existing styles */
}
:warning: Common Positioning Issues
- Plates not appearing side by side? Make sure you added
display: inline-block;
- Dining table not centered? Check that you have both
margin: 50px auto;
and a defined width- Images overflowing plates? Verify your image dimensions match the plate dimensions
CSS file not working
<link>
tag is correctly formatted: <link rel="stylesheet" href="style.css">
style.css
Images not displaying
assets/
Layout looks different than expected
Time: 2 minutes
Before submitting, ensure:
:information_source: Info Project Submission When you have completed your HTML Division project: