By the end of this lesson, you will:
:information_source: HTML Division Definition The HTML division element (
<div>
) is a container that helps organize content on your webpage. Think of it as an invisible box that groups related elements together!
As you build webpages, you'll add more and more HTML elements. The <div>
element helps you:
:memo: Note Remember: A
<div>
by itself is invisible! It only shows up when you add CSS styles to it.
Let's create your first div container!
index.html
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="section1">
<h1>Ways to make your cat happy</h1>
<p>Feed it and play with it.</p>
</div>
</body>
style.css
.section1 {
background-color: lightgreen;
}
What happens:
You can use multiple divs to create different sections on your page. Each div can have its own style!
:bulb: Tip Pro Tip: Use the
class
attribute to give each div a unique name. This helps you style them differently!
Let's see how it works:
index.html
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="section1">
<h1>Ways to make your cat happy</h1>
<p>Feed it and play with it.</p>
</div>
<div class="section2">
<h1>Ways to keep your cat healthy</h1>
<p>Feed it with good food and let it exercise.</p>
</div>
<div class="section3">
<h1>Experience sharing</h1>
<p>It is hard for me to feed the cat with medicine
when it is sick.</p>
</div>
</body>
style.css
.section1 {
background-color: lightgreen;
}
.section2 {
background-color: lightsalmon;
}
.section3 {
background-color: lightskyblue;
}
Result: You'll see three colorful sections:
Each section is now visually separate!
You can put divs inside other divs - like Russian nesting dolls! This creates a parent-child relationship.
:information_source: Think of it this way: A parent div is like a big box, and child divs are smaller boxes inside it.
Here's how to nest divs:
index.html
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="my-pet">
<div class="section1">
<h1>Ways to make your cat happy</h1>
<p>Feed it and play with it.</p>
</div>
<div class="section2">
<h1>Ways to keep your cat healthy</h1>
<p>Feed it with good food and let it exercise.</p>
</div>
<div class="section3">
<h1>Experience sharing</h1>
<p>It is hard for me to feed the cat with medicine
when it is sick.</p>
</div>
</div>
</body>
style.css
.my-pet {
background-color: tomato;
}
.section1 {
background-color: lightgreen;
}
.section2 {
background-color: lightsalmon;
}
.section3 {
background-color: lightskyblue;
}
Result: You'll see a layered effect:
Let's understand the family relationship between divs:
:memo: Note Quick Check: In our example:
- Parent:
<div class="my-pet">
- Children: All three section divs inside it
Before watching the video, remember these key points:
:information_source: Icon Definition Icons are small pictures or symbols that help users understand your website quickly. They're like visual shortcuts!
Icons make your website better by:
A favicon is that tiny icon you see in your browser tab! It helps users:
Let's create your first favicon! Follow these steps:
Click on your favorite icon
Select the 16 pixel option (favicons are tiny!)
Right-click on the icon and choose "Save image as..."
<head>
section:href
to point to your favicon file:Want to use your own picture as a favicon? Let's resize it to the perfect size!
:bulb: Tip Pro Tip: Choose a simple image that looks good when tiny!
Follow these steps:
Visit Favico.com at https://convertico.com/favicon/
Check that size is set to 16px x 16px, then click BROWSE
<head>
section:<link rel="icon" type="image/x-icon" href="favicon.ico">
Font Awesome gives you thousands of icons to make your website look amazing!
:information_source: What is Font Awesome? It's like a huge library of icons you can use anywhere on your website - social media icons, arrows, hearts, stars, and much more!
Let's add Font Awesome to your website:
Visit Font Awesome at https://fontawesome.com/start
Enter your email and click "Send Kit Code"
</body>
fa-2x
:<i class="fab fa-facebook fa-2x"></i>
Here are all the sizes you can use:
Class | Size | When to Use |
---|---|---|
fa-xs | 0.75em | Extra small - for tight spaces |
fa-sm | 0.875em | Small - slightly smaller than text |
fa-lg | One.33em | Large - a bit bigger than text |
fa-xl | One.5em | Extra large - stands out nicely |
fa-2x | 2em | 2x size - great for headers |
fa-3x | 3em | 3x size - for important icons |
fa-5x | 5em | 5x size - major focal points |
fa-7x | 7em | 7x size - hero sections |
fa-10x | 10em | 10x size - massive displays |
:bulb: Tip Quick Tip: Start with
fa-2x
for most icons, then adjust as needed!
You've learned a lot! Here's what you can do now:
Now it's your turn to practice what you've learned:
:memo: Note Remember: Practice makes perfect! Try different combinations and see what works best for your design.