The Document Object Model (DOM) is set of conventions by which web browsers access and manipulate objects within a web page.
What is most important to us as web designers learning CSS is the way the DOM organizes elements in a web page in a mathematical tree. We need to understand this tree structure and the concepts associated with it to use advanced CSS selectors.
Here is the element tree for the inline.html document that you
worked with in the exercises from the last lesson:
We will use this example to illustrate the relationships among elements in the tree.
The root of our element tree is the html element. It is
the only element at the top level of the tree.
A path is a sequence of connected elements moving down from a given
element away from the root. Each element in a path has to be below the
previous one, so section--p--sub and
footer--a--strong are paths, but a--footer--a
is not, because the first connection, a--footer, is going up
instead of down.
With an understanding of path, it is possible to describe the following relationships among elements in our element tree:
h1, section, and the footer elements
all have the body element as their parent.
section element has four children, all of which are paragraphs.
a elements that are children of the footer
element are siblings. So are the four p elements that are
children of the section element.
html) to the given element is called an ancestor of
that element. The body element is the ancestor of all the
p elements. The footer element is the ancestor
of two of the strong elements. The parent of a given element
is also its ancestor, but so is its parent's parent, and so forth.
kbd
element is the decendent of the section element. Two of the
strong elements are decendents of the footer
element.
kbd element.footer element.code element.html element at the root (top) of the element tree.head element has the required meta
and title elements as children to be a valid html 5 document,
and a style child element for CSS.body element has a header element, two
section elements, and a footer element, in that
order, as children.header element has an h1 element followed
by a nav element as children.nav element has five a elements as
children.section elements have the same children: an
h2 element followed by an h3 element followed by
an ol element followed by another h3 element and
then another ol element.ol elements have four li elements
as children.footer element has two a elements as
children, and each of the a elements has a single
strong element as a child.webskills.html with all the
elements from the element tree you drew in the previous exercise.
(Note: You should work from the diagram you created in the previous
exercise. Do not include any data or meta-data).<!DOCTYPE html>