4. Lists

The moment it's necessary to group elements we can turn to lists. If the components can fit in a chaotic order, where their placement isn't important, we call it an unordered list (list of ingredients, tasks, movies watched, archenemies...). And when a harmony is needed it's called an ordered list (steps for a cooking recipe, priorities, winners...).

Unordered

Tag <ul>
Description Unordered list.
Attributes Global
Type Block

Each element inside it will need the <li> tag.

Tag <li>
Description List item.
Attributes Global
Type Block

An example of its structure.

<ul>
    <li>Oil</li>
    <li>Flour</li>
    <li>Jam</li>
</ul>
  • Oil
  • Flour
  • Jam

Ordered

Tag <ol>
Description Ordered list.
Attributes reversed: Reverse the order.
start: Start.
type: Type of numbering (a, A, i, I and 1).
Type Block

An example of its structure.

<ol>
    <li>Preheat oven</li>
    <li>Mix the Flour with water</li>
    <li>Let it rest</li>
</ol>

The result will be the following.

  1. Preheat oven
  2. Mix the Flour with water
  3. Let it rest

If we wanted to change to descending order.

<ol reversed>
    <li>Preheat oven</li>
    <li>Mix the Flour with water</li>
    <li>Let it rest</li>
</ol>
  1. Preheat oven
  2. Mix the Flour with water
  3. Let it rest

Indicate the number it will start at.

<ol start="8">
    <li>Preheat oven</li>
    <li>Mix the Flour with water</li>
    <li>Let it rest</li>
</ol>
  1. Preheat oven
  2. Mix the Flour with water
  3. Let it rest

Or indicate what type of numbering. For example roman numerals.

<ol type="I">
    <li>Preheat oven</li>
    <li>Mix the Flour with water</li>
    <li>Let it rest</li>
</ol>
  1. Preheat oven
  2. Mix the Flour with water
  3. Let it rest

Sublists

To achieve elements in a hierarchy, one inside another, we must repeat the previous structure between the appropriate <li> tags.

<ol>
    <li>Preheat oven</li>
    <li>Mix the Flour with water</li>
    <ul>
        <li>Let's not forget to stir well</li>
        <li> Watch out for lumps</li>
    </ul>
    <li>Let it rest</li>
</ol>
  1. Preheat oven
  2. Mix the Flour with water
    • Let's not forget to stir well
    • Watch out for lumps
  3. Let it rest

They can be mixed in all possible combinations.

<ul>
    <li>Oil</li>
    <li>Flour</li>
    <li>Jam</li>
    <ul>
        <li>Strawberry</li>
        <li>Plum</li>
    </ul>
</ul>
  • Oil
  • Flour
  • Jam
    • Strawberry
    • Plum
<ul>
    <li>Oil</li>
    <li>Flour</li>
    <li>Jam</li>
    <ul>
        <li>Strawberry</li>
        <ul>
            <li>Large</li>
            <li>Small</li>
        </ul>
        <li>Plum</li>
    </ul>
</ul>
  • Oil
  • Flour
  • Jam
    • Strawberry
      • Large
      • Small
    • Plum

Navigation menu

To create a set of ordered hyperlinks that can be used to navigate the site we must follow a fixed structure (which is a standard nowadays). The <nav> tag, inside it an unordered list which in turn contains hyperlinks in each element.

Tag <nav>
Description Sectioning content for navigation.
Attributes Global
Type Block

Later we'll discover the tags called Sectioning content; for now we'll declare it to indicate where our menu is located.

<nav>
  <ul>
    <li><a href="#">Home</a></li>
    <li><a href="#">Portfolio</a></li>
    <li><a href="#">Shall we talk?</a></li>
  </ul>
</nav>

Definition lists

Represents a list of terms with their corresponding definition.

We'll need 3 tags.

Tag <dl>
Description Container of the definition list.
Attributes Global
Type Block
Tag <dt>
Description Definition title.
Attributes Global
Type Block
Tag <dd>
Description Definition description.
Attributes Global
Type Block
<h1>Extinct animals</h1>

<dl>
    <dt>Smooth handfish</dt>
    <dd>The red handfish is a close relative.</dd>
    <dt>The Tasmanian wolf</dt>
    <dd>They were fierce but shy animals that fed on rodents and kangaroos and were hunted to extinction by humans.</dd>
    <dt>The passenger pigeon</dt>
    <dd>The most abundant species in the Americas a century ago. None remain.</dd>
</dl>

Extinct animals

Smooth handfish
The red handfish is a close relative.
The Tasmanian wolf
They were fierce but shy animals that fed on rodents and kangaroos and were hunted to extinction by humans.
The passenger pigeon
The most abundant species in the Americas a century ago. None remain.
Activity 1

Create the following page using lists.

Newspapers activity

Activity 2

Create the following page using lists and sublists.

Series activity

Activity 3

Create the following page using an ordered list.

Fix computer activity

Activity 4

Create the following page using a list accompanied by the nav tag.

Simple menu activity

Activity 5

Use a definition list to report which were the largest dinosaurs that have ever existed. The title will be their name and the description their measurements (at minimum, you can include more information).

This work is under a Attribution-NonCommercial-NoDerivatives 4.0 International license.

Desafíos de programación atemporales y multiparadigmáticos

Desafíos de programación atemporales y multiparadigmáticos

Te encuentras ante un librillo de actividades, divididas en 2 niveles de dificultad. Te enfrentarás a los casos más comunes que te puedes encontrar en pruebas técnicas o aprender conceptos elementales de programación.

Buy the book

Will you buy me a coffee?

This is how I keep writing without ads or paywalls.

Comments

There are no comments yet.