Web Design |
lists |
||
main menushelp pagesprinter-friendly/text-only version |
The small family of tags which produce bulleted and numbered lists are very useful. You use them to produce effects like this: Simple Sweet & Sour PrawnsIngredients (serves 2):
Method:
Both types of list are shown here. The first is a bulleted list or, officially, an unordered list. The second, the numbered list, is properly known as an ordered list. Both are created with two tags working in tandem. By the way, it's hard to say whether list tags are block-level or inline. They have features of both and it's almost best to think about them as a third, separate group of text formatting tags. Each list, as a whole, is bounded by the main list tag: <ul> and <ol> respectively. Then each list item is then bounded (in both cases) by <li> tags. The code for the first list (most items omitted for clarity) therefore looks like this:
<h3>Simple Sweet & Sour Prawns</h3> The code for the second list is identical in structure only here the <ul> tags are replaced by <ol> ones. Note the way the text is formatted on screen, with a paragraph indent, as well as the tags just providing the bullets or numbers. Closing </li> tags are often omitted, but shouldn't be as this can cause style sheet formatting to fail. You are always safer putting closing tags in. Style sheet formatting of the <li> tag is usually shared with that of the <p> tag, although it doesn't have to be. This is an opportune moment to highlight the way in which you can apply formatting to more than one tag. The style sheet entry for both these tags in this site's style sheet looks like this:
p, li { font-family: "Lucida Sans Unicode", Verdana, Arial, sans-serif; You can define styles for <ul> and <ol> as well, but remember the idea of inheritance. <li> tags are nested within these other two tags so there is no need to define styles on both. In practice I find it is best to define the appearance of list text in the style definition of the <li> tag, and use style definitions on the other two tags only to define the appearance of the bullets. You can do this with a property, list-style-type. For details see the style sheet reference page. In fact you can also use small images or icons as list bullets: there is an example at the top of the page which introduces images (the yellow stars). Again, see the style sheet reference page (and don't try this until you've found out more about images anyway). Finally, you can use an attribute called start if you want to make your ordered lists start at something other than 1. It's quite straightforward: just do something like this: <ol start="5">. This is structural information so you can't do this with styles but must use the attribute. |
Material on this site is © Drew Whitworth, 2005 Permission will usually be given to reproduce material from this site for non-commercial purposes, if credit is given. For enquiries, e-mail Drew at andrew [dot] whitworth [at] manchester [dot] ac [dot] uk.