To make HTML work, you must learn to put block elements within other block elements and to put inline elements into other inline elements and into block elements. This process is called nesting. Consider the following nested list:
> This is the first bulleted item
> This is the second bulleted item
> This is a numbered item
> This is another numbered item
> This is a third numbered item
> This is the third and final bulleted item
The following HTML will create the same thing:
<UL>
<LI> This is the first bulleted item
<LI> This is the second bulleted item
<OL>
<LI> This is a numbered item
<LI> This is another numbered item
<LI> This is a third numbered item
</OL>
<LI> This is the third and final bulleted item
</UL>
First, you should know—and you may already know—that the rules about nesting are not enforced by all browsers. What this means is if you break them, there might not be any visible penalty today. In the future, as more elements are introduced, nesting rules will have to be more strictly enforced.
Now the rules:
1. Close your elements in the reverse of the order you opened them: If you have a paragraph in which you identify a book title, which you both bold and italicize, you must close the inner element before you close the outer element.
In the following example, notice the B element is the last one opened and, therefore, is the first one closed. The P element, which is the only block-level element, is the first one opened; therefore, it is the last one closed.
<P>One book I can highly recommend is Dostoyevsky’s
<I><B>Crime and Punishment</B></I></P>.
2. Always close inline elements before you close the block element that contains them: This is a subset of the previous rule. But the consequences of breaking it can be visible on your page. If you fail to close an inline element when you intend to, you could end up with bolded or italicized and bolded text on the rest of your page.
3. Sometimes opening a new block automatically closes the previous open block: You need to play this by ear, but there are times when beginning a new block element automatically ends the previous block element. One time this absolutely works is with paragraphs. You simply can’t put a P element within another P element. Go ahead and try it. When your browser sees the second P element, it automatically closes the first one. However, you certainly can put a list within another list. Starting a second UL element doesn’t close the previous UL element. You can also put a P element into a UL element, which doesn’t close it either.


LinkBack URL
About LinkBacks
Reply With Quote

LinkBacks Enabled by vBSEO
Bookmarks