Generating a fictional list of items in a sequential order

I am managing a website that focuses on displaying the line of succession to the British crown. The main content of the site is structured as an ordered list using the <ol> tag.

However, there is a unique challenge. Individuals occasionally drop out of the line of succession (often due to marriage to a Catholic). For example, Prince Michael of Kent was listed as 16th in line on 1978-06-29, but disappeared from the list the following day after marrying a Catholic.

Currently, I simply remove excluded individuals from the list altogether. However, I would prefer to include them while visually distinguishing their entries with a "dimmed" typeface. This poses another issue because it disrupts the ordered sequence of the list when some entries are omitted from numbering.

To address this challenge, I have considered several options:

  • Switching to a <ul> and manually assigning numbers while styling to remove bullets and adjust numbering indentation.
  • Transitioning to using outdented paragraphs instead of lists.
  • Utilizing a table format with a narrow first column for listing.

I am curious if there exists a CSS or HTML trick that could simplify achieving the desired outcome. Is there a more straightforward approach to handle this situation?

Update: The current HTML structure is as follows:

<ol>

  <li itemscope itemtype="http://schema.org/Person"><span itemprop="name">The Prince Charles, Prince of Wales</span>
            <br><span class="small">Age 69
    (born <a title="Line of Succession on 14 November 1948" href="/1948-11-14">14 November 1948</a>),
    <br>Son of the sovereign</span></li>

  <li itemscope itemtype="http://schema.org/Person"><span itemprop="name">Prince William, Duke of Cambridge</span>
            <br><span class="small">Age 35
    (born <a title="Line of Succession on 21 June 1982" href="/1982-06-21">21 June 1982</a>),
    <br>Grandson of the sovereign</span></li>

  <li itemscope itemtype="http://schema.org/Person"><span itemprop="name">Prince George of Cambridge</span>
            <br><span class="small">Age 4
    (born <a title="Line of Succession on 22 July 2013" href="/2013-07-22">22 July 2013</a>),
    <br>Great grandson of the sovereign</span></li>

  <li itemscope itemtype="http://schema.org/Person"><span itemprop="name">Princess Charlotte of Cambridge</span>
            <br><span class="small">Age 2
    (born <a title="Line of Succession on 02 May 2015" href="/2015-05-02">02 May 2015</a>),
    <br>Great granddaughter of the sovereign</span></li>

  ...
</ol>

The CSS styling is primarily based on Bootstrap 4.0 standards, except for the custom styling applied in this section:

span.small {
  font-size: 75%;
}

Answer №1

To incorporate numbering in your list items with CSS, you can utilize the css counters technique. Remember to assign a class to the element that should be excluded from counting.

Sample Code Snippet

ul {
  font: 13px Verdana;
  list-style: none;
  counter-reset: list;
  padding: 0;
}

ul>li:not(.disable):before {
  counter-increment: list;
  content: counter(list) ": ";
  position: absolute;
  left: 0;
}

ul>li {
  position: relative;
  padding-left: 20px;
}

ul>li.disable {
  opacity: .5;
}
<ul>
  <li>Text</li>
  <li>Text</li>
  <li class="disable">Text</li>
  <li>Text</li>
  <li>Text</li>
  <li>Text</li>
  <li>Text</li>
  <li>Text</li>
</ul>

Answer №2

You have the option to utilize CSS counters to achieve this.

ol {
  counter-reset: item;
  list-style: none;
  margin: 0;
  padding: 0;
}

ol li {
  display: block;
  padding: 0 0 0 2.5em;
  margin: 0;
  position: relative;
}

ol .counted:before {
  content: counters(item, ".") " ";
  counter-increment: item;
  position: absolute;
  left: 0;
  top: 0;
  display: inline-block;
  width: 2.5em;
}

ol .level1>li {
  margin: 0;
  padding-left: 0;
}

ol .level1>.counted:before {
  left: -2.5em;
  font-weight: normal;
}


ol .level2>.list-item {
  padding-left: 2.5em;
}

ol .level2>.list-item:before {
  left: -1em;
  width: 3.5em;
}

.not-counted {color:green;}
<ol>
  <li class="counted">
    this is counted
    <ol class="level1">
      <li class="counted">
        this is counted
      </li>
      <li class="not-counted">
        this is not counted
      </li>
      <li class="counted">
        this is counted
        <ol class="level2">
          <li class="counted">
            this is counted
          </li>
          <li class="not-counted">
            this is not counted
          </li>
          <li class="counted">
            this is counted
          </li>
        </ol>
      </li>
    </ol>
  </li>
  <li class="not-counted">
    this is not counted
  </li>
  <li class="counted">
    this is counted
  </li>
</ol>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What could be causing the input submit in my form to be unresponsive when clicked?

I'm stumped on what's causing the issue. My sign-up form seems to be malfunctioning - when I click the "Complete Registration" button, nothing happens! The form doesn't even submit. Here is the HTML structure: <!DOCTYPE html> <html ...

The ion-datetime in Ionic 4 ensures that the floating label always remains visible, even when the input

When an ion-datetime field in Ionic 4 has no value, the label always floats as shown below. Here is my code snippet: <form [formGroup]="statusHandlerForm"> <ion-item class="input-container " align-items-center no-padding> <ion-la ...

The issue arises when attempting to apply CSS styles to an existing component or body tag,

I am currently working on an Angular 7 project where I have a requirement to dynamically load a component using routes. However, when I try to add styles for the body tag and existing component tags in the dynamically loaded component style-sheet, they do ...

Is it possible to showcase a dropdown list within a constantly changing table?

I have a table code snippet that I need help with <fieldset class="tabular"><legend><%= l(:redmine_taskjuggler) %></legend> <%= labelled_fields_for(@issue) do |f| %> <div id="taskjuggler" class="attributes"> <div cl ...

Something is amiss with the PHP email validation functionality

I have been facing issues with the functionality of my form that uses radio buttons to display textboxes. I implemented a PHP script for email validation and redirection upon completion, but it doesn't seem to be functioning correctly. The error messa ...

Master the art of positioning in three.js framework

I am a beginner in javascript and three.js, and I am currently exploring how to determine the 3d positions on a webpage. For instance, I want to place a point light at the coordinates (50,20,10) in x, y, z values. How can I determine where these x, y, z va ...

Want to learn how to display a description below a photo when you hover over it in a photo gallery?

I am currently creating a basic photo gallery where hovering over a thumbnail displays an enlarged photo below it. My goal is to also have text displayed inside a white text box when hovering over each thumbnail, with unique descriptions for each. I need ...

Incorporating @font-face webfonts into a Jekyll project

I'm currently working on incorporating webfonts into a Jekyll build. Interestingly enough, the fonts show up perfectly fine when I view them locally, but once I push my project to a live environment, the fonts mysteriously disappear. To make matters w ...

The edges of the cube are not joined together

Looking for a 3D transform cube that can freely flip left and right, with the button fitting into it perfectly. I've found the CSS code to achieve this, but when I set the width of the ".cube" below 200px, the borders of the cube don't connect. I ...

Difficulty encountered when positioning a container using BootStrap 4

As a newcomer to the world of web development, I encountered an issue while trying to align a container on my webpage. Despite my efforts to center the container using (line 30), the page seems to update but there is no visible change. Can anyone help me ...

Shell script for swapping all occurrences of :*; with a comma

Below are some CSS color variables defined in hex: --state-success-text: #3c763d; --state-success-background: #dff0d8; To create a comma-separated list of these color variables, the output should look like this: state-success-text, state-success ...

"Create a Single-Page Bootstrap Website with a Responsive Design showcasing PHP Code within the Contact Form

Working on the final touches of a single-page responsive website project for a client. Utilizing a Bootstrap contact form located at the bottom of the HTML document. The PHP code is unexpectedly displaying in the text fields of the contact form. I've ...

Can the parent document interact with Shadow DOM elements?

When it comes to user-created shadow DOM elements, this question focuses more on accessibility using the date input type: For instance, let's say there is a date input on a webpage. After some editing, the shadow DOM markup for this element (in Chrom ...

jQuery Show/Hide Not Working Properly

I'm attempting to showcase one Tweet at a time and have it rotate through different tweets. I'm facing an issue where it works correctly on one type of page, but not on the other. Could this be due to a CSS precedence rule overriding the function ...

PyQt TreeView scrollbar obstructing the header

I've been experimenting with the QTreeView widget (instead of QListView) in order to have a horizontal header. Additionally, I wanted to use stylesheets to customize the colors and appearance of the header and scrollbars. However, there is an issue w ...

Create a bootstrap table with td elements that have no wrap for their content

I am currently developing an application using springboot, thymeleaf, and bootstrap. Here is the snippet of the html code I'm working with: <!doctype html> <html lang="en" xmlns:th="http://www.thymeleaf.org"> <h ...

Steps for removing all inline styles within an element:1. Access the element's

I have a group of span elements containing texts generated by tinymce. <span class="ArticleSummary"> This content is produced using a text editor and may include various inline styles. </span> Typically, this text includes numerous inline s ...

The height of adjacent divs should be uniform, resize seamlessly, and contain an absolutely positioned element within

Is there a way to make these neighboring divs the same height, responsive to browser window resizing, and with icons positioned on the corners? This method using display:table-cell works in most browsers but fails in Firefox due to a bug that causes the ic ...

Using Selenium IDE to click on a checkbox within a table row

Currently, I am utilizing Selenium IDE to navigate through a table with multiple rows and columns. Each row within the table contains its own checkbox for selection purposes. In my attempt to search for a specific row, I have been using the following comm ...

Every time I attempt to create a detail page for a table, I am consistently greeted with an error message

Error: Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in /var/www/2909kher/entabell/detaljer.php on line 23 <!doctype ...