Skip to content

Commit 02e4292

Browse files
authored
feat(curriculum): Add interactive examples to div lesson (freeCodeCamp#62634)
1 parent b4ccd9d commit 02e4292

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

curriculum/challenges/english/blocks/lecture-html-fundamentals/670803abcb3e980233da4768.md

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,48 @@ challengeType: 19
55
dashedName: what-are-div-elements
66
---
77

8-
# --description--
8+
# --interactive--
99

10-
Now that we understand what HTML is, let's move onto the fun stuff! I am going to look at the Content Division Element - or in other words, the *div*:
10+
The `div` element is used as a container to group other elements.
1111

12-
```html
13-
<div></div>
14-
```
15-
16-
I like to think of the `div` as a beautiful being that can be anything you want it to be. We can give a `div` a `height`, we can give it a `width`, and we can give it a background color using CSS - or in other words styling, which we will cover in lessons coming up.
12+
Here is an example of a `div` element. Add another paragraph element inside of the `div` element and see the changes in the preview window.
1713

18-
We can also use it in a very basic form without styling, to hold other elements together. So for example, we can create a `div` and put a heading in it, and put a paragraph in it, and now these two elements will be grouped together:
14+
:::interactive_editor
1915

2016
```html
2117
<div>
22-
<h1>I am a heading</h1>
23-
<p>I am a paragraph</p>
18+
<p>Example paragraph element.</p>
19+
2420
</div>
2521
```
2622

27-
Just be aware that there might be better elements to use when grouping these together. You might choose a `section` element, for example:
23+
:::
24+
25+
You will mainly use the `div` element when you want to group HTML elements that will share a set of CSS styles. You will learn more about CSS in future lessons and workshops.
26+
27+
Even though the `div` element is commonly used in real world codebases, you should be careful not to overuse it. There are times when another element would be more appropriate.
28+
29+
For example, if you wanted divide up your content into sections, then the `section` element would be more appropriate than a `div` element.
30+
31+
Add another `section` element below the first one. Then inside of the `section` element, a `h2` and `p` elements. You can use whatever text you like and you will see the changes in the preview window.
32+
33+
:::interactive_editor
2834

2935
```html
3036
<section>
31-
<h1>I am a heading</h1>
32-
<p>I am a paragraph</p>
37+
<h2>Mammals</h2>
38+
<p>Mammals are warm-blooded animals with fur or hair. Most give birth to live young.</p>
39+
<ul>
40+
<li>Lion</li>
41+
<li>Elephant</li>
42+
<li>Dolphin</li>
43+
</ul>
3344
</section>
3445
```
3546

36-
This is because the `section` element has semantic meaning. Semantics are the meaning of words or phrases in a language. In HTML, which is a language, elements have their own semantic meaning too. So, this means if you use a `section` element, the browser will pick up its semantic meaning and understand to treat this as a section - on desktops, mobiles, you name it. 
47+
:::
3748

38-
We will dive into this topic further later on. For now, just know that the `div`, does not have this. It's like a mysterious ghost. Let's see what else we can do to a `div`, in the next lesson.
49+
The `section` element has semantic meaning over the `div` element which is not semantic. Semantics are the meaning of words or phrases in a language. In HTML, which is a language, elements have their own semantic meaning too. So, this means if you use a `section` element, the browser will pick up its semantic meaning and understand to treat this as a section - on desktops, mobiles, you name it. 
3950

4051
# --questions--
4152

0 commit comments

Comments
 (0)