Relationships?

Sibling to p, but also grandchild of body

Sibling to h1, but also grandchild of body

Link - https://www.codecademy.com/courses/learn-html/lessons/intro-to-html/exercises/structure-html?action=resume_content_item

In the above given html, they have said that

and

are siblings because they are at same level . Then why not and

?:thinking:

My doubt is how can you define a level ?

Each element has a relation to the other elements in a html page. Similar to what a person is to other people within his family. Siblings are elements which have the same parent element. They are the children of this parent and siblings to each other.

<div id="parent">
  <h1 id="child1">...</h1>
  <h2 id="child2">...</h2>
</div>

This parent element may also have a sibling with an element of the same generation. These parents to children, are siblings to each other.

<div id="parent1">
  <h1 id="child1_1">...</h1>
  <h2 id="child1_2">...</h2>
</div>
<div id="parent2">
  <h1 id="child2_1">...</h1>
  <h2 id="child2_2">...</h2>
</div>

Thanks @janneslohmeijer❤️
My doubt is that how you can a decide a particular element as a sibling to other ?

In the replied example
why h1 and h2 elements are childs to div element ?

Because they are both inside the div element. They are child of the div, and siblings to eachother.

It means that what ever the elements under a div element will be siblings to each other .

1 Like