Prev | Current Page 123 | Next

Tommy Olsson and Paul O'Brien

"The Ultimate CSS Reference"



If we apply the selector to the HTML block below, the paragraph is matched by the
selector even though it appears not to be adjacent to the heading:

Heading


Lorem ipsum dolor sit amet.

The selector above matches this paragraph.


The selector matches the paragraph in this case because the node between them is
a text node rather than an element node. So if you look at element nodes only, the
heading and the paragraph are adjacent siblings.
Element Nodes and Text Nodes
A browser builds an internal document structure, called the Document Object Model
(DOM), from a web page. This model consists of nodes of different types. The
relationship between the nodes can be visualized as an upside-down tree, which is
why the model is often referred to as the DOM tree.
The two main types of nodes in this tree are element nodes and text nodes. Element
nodes correspond to HTML elements, while text nodes correspond to the textual
contents of element nodes. For instance, a fragment like Important! will
create one element node for the em element, and that element node will contain a
text node with the text Important!.


Pages:
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135