Get Down With Markup - Method B: The bullet that bites
(Page 3 of 9 )
<li>Apples<br />
<li>Spaghetti<br />
<li>Green Beans<br />
<li>Milk<br />
Most competent browsers will insert a bullet to the left of a list item when the <li> element is used. One might use Method B to achieve those results, adding the <li> by itself when a bullet is desired. However, some of those same competent browsers won’t display the bullet when an <li> element isn’t contained within one of its proper parent, the mighty <ul>. The <li>’s other parent is the <ol> element, for “ordered lists,” which I’ll discuss further on in the book.
The bullet does help the wrapping issue to a certain extent. A new grocery item would be signified by a bullet, to its left. If an item wraps to the next line, the absence of a bullet should be enough to distinguish itself from being a whole new item. But there is something else wrong with Method B, aside from its resulting display: It’s not valid.
Validation, please
According to the W3C’s XHTML 1.0 specification, all tags must eventually close—and if we were to go ahead and open an <li> for each grocery item, without closing it at the other end as in the example, shame on us!
We’ve mimicked the automatic line-breaking that occurs when a proper unordered list is used by adding the <br /> tag at the end. But there’s a better way.
It’s valuable to get used to the idea of writing valid markup, consistently. By ensuring our markup is valid, we’ll worry less about problems that may occur because of unclosed or improperly nested elements in the future. Not to mention that if anyone else is looking at our code, it’s easier for everyone involved to dive in and understand exactly what’s going on.
Be sure to use the W3C’s online validation tool (http://validator.w3.org/) to validate your files by URI or file upload. You’ll be happy you did in the long run.
This chapter is from Web Standards Solutions: The Markup and Style Handbook by Dan Cederhold (Apress, 2004, ISBN: 1590593812). Check it out at your favorite bookstore today. Buy this book now.
|
Next: Method C: Getting closer >>
More Web Standards Articles
More By Apress Publishing