2079 4

CSC329 ยท 2079 ยท 5 marks

Write a HTML script to generate following list of items; 1. Coffee : I. Black coffee II. Green coffee 2. Tea A: Black tea B. Green tea

Write a HTML script to generate following list of items; 1. Coffee : I. Black coffee II. Green coffee 2. Tea A: Black tea B. Green tea [5]

Web TechnologyChapter 2: Hyper Text Markup LanguageLists

HTML Script for Nested Lists

Analysis of Required Output

The question requires:

  • Outer ordered list (numbered: 1, 2) for Coffee and Tea
  • Inner ordered list under Coffee with Roman numerals (I, II) for Black coffee and Green coffee
  • Inner ordered list under Tea with uppercase letters (A, B) for Black tea and Green tea

HTML Code

<!DOCTYPE html>
<html>
<head>
    <title>Nested List Example</title>
</head>
<body>

    <ol type="1">

        <li>Coffee
            <ol type="I">
                <li>Black coffee</li>
                <li>Green coffee</li>
            </ol>
        </li>

        <li>Tea
            <ol type="A">
                <li>Black tea</li>
                <li>Green tea</li>
            </ol>
        </li>

    </ol>

</body>
</html>

Output

1. Coffee
      I.  Black coffee
      II. Green coffee
2. Tea
      A. Black tea
      B. Green tea

Key Points (from notes)

Tag / AttributePurpose
<ol>Ordered list (numbered by default)
<li>Each list item
type="1"Numeric numbering (1, 2, 3...)
type="I"Uppercase Roman numerals (I, II, III...)
type="A"Uppercase alphabetic (A, B, C...)

Note: The type attribute in the <ol> tag is used to change the list marker style. Nesting is achieved by placing one <ol> inside a <li> of the outer <ol>.

Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.