HTML5, CSS3, and JavaScript Fourth Edition

(Ben Green) #1

CHAPTER 4. HTML TAGS AND ATTRIBUTES 40


4.2.4 Nesting and Overlapping Markup


Let’s define a couple of words: nesting and overlapping. Markup can usually
be nested, but normally overlapping is not allowed.


Bynested tagswe mean:


aaa bbb ccc

In this case, the whole item, aaa bbb ccc, is tagged with the x tag, and a
smaller part in the middle, bbb, is tagged with both the x tag and the y tag.


Exam Question 59(p.339):When one set of tags begins and ends totally
inside another set of tags, what do we call that?
Acceptable Answer:nesting or nested


Byoverlapping tagswe mean:


aaa bbb ccc

In this case, we apparently intend the first two-thirds, aaa bbb, to be tagged
with the x tag, and the last two-thirds, bbb ccc, to be tagged with the y
tag, with the middle third, bbb, tagged with both the x tag and the y tag.


Overlap is forbidden.


In most cases, the solution is to end the tag and then restart it, like this:


aaa bbb ccc

All you really need to know is that nesting is okay, and overlapping is not.


In case you are curious, here is why:


After your webpage is loaded into the browser, it is no longer stored as
HTML. Instead, it is stored as a tree-like structure called theDOM(doc-
ument object model). Trees cannot handle overlaps.


The browser may fix it for you automatically, but it is not required to. A
validator will just say it is wrong.


Exam Question 60(p.339):What is wrong with this ordering:.........?
Acceptable Answer:overlap


Exam Question 61(p.339):What is wrong with this ordering:.........?
Acceptable Answer:nothing

Free download pdf