You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: curriculum/challenges/english/blocks/lecture-html-fundamentals/670803abcb3e980233da4768.md
+26-15Lines changed: 26 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,37 +5,48 @@ challengeType: 19
5
5
dashedName: what-are-div-elements
6
6
---
7
7
8
-
# --description--
8
+
# --interactive--
9
9
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.
11
11
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.
17
13
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
19
15
20
16
```html
21
17
<div>
22
-
<h1>I am a heading</h1>
23
-
<p>I am a paragraph</p>
18
+
<p>Example paragraph element.</p>
19
+
24
20
</div>
25
21
```
26
22
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
28
34
29
35
```html
30
36
<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>
33
44
</section>
34
45
```
35
46
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
+
:::
37
48
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.
0 commit comments