A div that can't be broken
This is more theoretical, I don't have a use for it currently, but would be nice. I would like to create a div layout in which each section cannot be broken by mismatched tags inside of it.
A simple model:
<div id="navbar">
</div>
<div id="content">
**blah blah blah </div>**<!-- assume this line came from a php include -->
blah blah blah
</div><!-- still related to #content despite the bogus /div above it. -->
Has anyone ever tried to accomplish this, or 开发者_如何学编程is this a fools errand?
There is no way to do this. If you have an opening <div>
tag, the next </div>
tag will close it. Period. Case closed.
If you don't want your <div>
to be closed early, then don't print the bogus </div>
.
There's always
<div>
<![CDATA[ blah blah </div> ]]>
</div>
But then you can't really make use of the tags inside the CDATA section.
Frames (inline or otherwise) provide some isolation. Anything inside the frame won't close tags outside the frame.
That does happen but the solution is sanitizing what you will output properly, this **blah blah blah </div>**<!-- assume this line came from a php include -->
should not be printed, strip the tags or check for valid html before doing so.
精彩评论