Constructing markup for text and subtext in a meaningful manner

I am in the process of creating a roster of Employees and their dependents on a webpage and I could use some guidance on the best way to structure this information.

Here is an example of the content on my page:

<div>
John Smith
Employee - 03/01/1980
</div>

<div>
Betty Smith
Spouse- 04/19/1981
</div>

<div>
Robert Smith
Child- 06/04/2002
</div>

The individual's name will be styled differently from their role and birthdate below. Should I utilize span, ul, p, or another method? Your help is appreciated.

Answer №1

A great idea is to utilize definition lists <dl>, <dt> and <dd>.

The HTML <dl> element is perfect for organizing groups of terms and their corresponding descriptions. It can be used for glossaries or displaying metadata like key-value pairs.

dt, dd {
  margin: 0;
}
dt {
  color: green;
}
dd {
  color: gray;
  margin-bottom: 10px;
}
<dl>
  <dt>John Smith</dt>
  <dd>Employee - 03/01/1980</dd>
  <dt>Betty Smith</dt>
  <dd>Spouse- 04/19/1981</dd>
  <dt>Robert Smith</dt>
  <dd>Child- 06/04/2002</dd>
</dl>

Answer №2

When presenting a list of employees along with their dependents in a tabular format, you can utilize the following formatting:

body {
  font-family: sans-serif;
}

table {
  margin: 1em 0;
  width: 100%;
}

table th, td {
  border-bottom: 1px solid #ccc;
  font-size: 14px;
  padding: 4px;
}

table caption {
  font-size: 14px;
  background: #ccc;
  padding: 4px;
}
  <ul>
    <li>
      John Smith - 03/01/1980
      <table cellspacing="4">
        <caption>
          Dependents
        </caption
        <thead>
          <tr>
            <th>Name</th>
            <th>Relation</th>
            <th>Date of Birth</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>Betty Smith</td>
            <td>Spouse</td>
            <td>04/19/1981</td>
          </tr>
          <tr>
            <td>Robert Smith</td>
            <td>Child</td>
            <td>06/04/2002</td>
          </tr>
          <tr>
            <td>Sarah Smith</td>
            <td>Child</td>
            <td>04/04/2004</td>
          </tr>
        </tbody>
      </table>
    </li>
  </ul> 

Answer №3

If you decide to utilize lists for this task, you can approach it in the following manner:

ul {
  padding-left: 0px;
}
  
li {
  list-style-type: none;
}

.name {
  background: #AAAAFA;
  height: 35px;
  width: 200px;
  font-size: 14px;
  font-weight: bold;
}

.role {
  background: #AAFAAA;
  height: 25px;
  width: 200px;
  font-size: 12px;
  margin-bottom: 10px;
}
<div>
  <ul>
    <li class="name">John Smith</li>
    <li class="role">Employee - 03/01/1980</li>
  </ul>
</div>

<div>
  <ul>
    <li class="name">Betty Smith</li>
    <li class="role">Spouse-04/19/1981</li>
  </ul>
</div>

<div>
  <ul>
    <li class="name">Robert Smith</li>
    <li class="role">Child-06/04/2002</li>
  </ul>
</div>

Hoping this solution proves useful, Best regards

Answer №4

The top way to structure your code for optimal readability and user experience is:

<div class="grid_1 title">Name</div><div class="grid_1 title">Employee</div>
<div class="grid_1">Name_1</div><div class="grid_1">Employee_1</div>
<div class="grid_1">Name_2</div><div class="grid_1">Employee_2</div>
<div class="grid_1">Name_3</div><div class="grid_1">Employee_3</div>
<div class="grid_1">Name_4</div><div class="grid_1">Employee_4</div>

To achieve this layout, use the following CSS:

.grid_1 {float: left}

This method of structuring content lends itself well to responsive web design, allowing for easy viewing on various devices such as mobile phones and tablets.

With this layout, a single profile appears in a vertical stack for easy reading. However, when multiple profiles are displayed on a page, our brains naturally scan for rows of information arranged horizontally, similar to a table format. This intuitive layout makes it easier for users to find specific data points and make comparisons among different entries. Adding additional columns can be done seamlessly without disrupting the overall structure.

This grid-based approach is preferred over traditional tables due to its enhanced readability on smaller screens, making it ideal for modern web designs that prioritize responsiveness.

Answer №5

Creating your own elements: https://developer.mozilla.org/en-US/docs/Web/Web_Components/Custom_Elements

The main feature of version 1 custom elements is the CustomElementRegistry.define() method, which allows you to define a brand new custom element. This newly defined element will then utilize the specified class for all instances, rather than the default HTMLUnknownElement. Custom elements can also be built upon a native element such as <button>, using the syntax <button is="my-button">; these are known as customized built-in elements.

By incorporating custom elements, your HTML structure could appear like this:

<profile-card>
    <profile-name>Jane Doe</profile-name>
    <profile-description>Manager - 06/15/1990</profile-description>
</profile-card>

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

Position the <i> element to the right side of the <div> element in an HTML document

I am trying to make this <i> element align to the right within my <div>. Here is the HTML code I have so far: <div class="container-fluid p-1 bg-primary text-white d-flex align-items-center justify-content-center"> <h2&g ...

"Stuck: CSS Div Transition Effect Refuses to Cooper

I am looking to incorporate a transition on my div when it is clicked. I've tried using jQuery with this example: http://jsfiddle.net/nKtC6/698/, but it seems to not be working as expected. So, I want to explore another example using CSS: http://jsfid ...

Creating a JavaScript function that responds to multiple click events

Can someone please help me out? I have the link to the output of my work below using JavaScript and HTML: My goal is for only one circle to be active when clicked, while the others are disabled. Currently, when I click on a circle and then another one, bo ...

Restrict printing loops within the designated division layer

Is there a way to limit the number of rows displayed horizontally when using foreach? I only want to display 7 rows. Can this be achieved with CSS or pagination? Here is an image illustrating the issue: https://i.sstatic.net/yJx3N.png Currently, it print ...

Create a fixed content scroll effect with an inset box-shadow

I recently stumbled upon a solution at Stack Overflow that effectively created an inset box shadow beneath content. However, I encountered an issue when the outer container div needed to be scrolling due to overflow - the inner div with the box shadow woul ...

What methods can I use to stop Meta and Title tags from injecting when I import PHP files into an HTML document?

In my PHP document, I took out the Title and Meta tags from the header section, leaving it empty: <!doctype html> <html> <head> </head> <body> <?php require '/DBConnect.php'; //More code here that generates my ou ...

Unable to load circles on page refresh with amCharts Maps

I am experiencing an issue with the functionality of my amCharts maps. Whenever I refresh the page, the circles that are supposed to be displayed disappear. However, when I zoom in, the circles reappear. This problem has me puzzled, and I'm not sure ...

Gaining a comprehensive understanding of media queries

Hello everyone, I need some help with media queries. I've been working on a website that is already responsive. However, I am required to write the code in a child theme rather than directly in the original files. When I attempt to add new media quer ...

Retrieve data from TypeScript file (.ts) and use it in an HTML document

Recently I started learning Typescript and HTML as I work on building an Angular2 application. At the moment, I have a TypeScript file that resembles the following structure: import {Http, Headers} from 'angular2/http'; import {Component} from & ...

unable to insert logo into HTML

I am customizing an HTML template, but the dimensions of the logo in the template are smaller than my logo. Despite adding my logo to the template, it is not showing up. @media (max-width: 673px) { #logo { margin-left: 20px; } } #header #logo ...

Certain rows in the table should maintain a consistent width, while others are allowed to vary

I am dealing with a table containing certain rows Some of these rows are visible, while others are hidden. The visible rows at the start are referred to as: mainTrs. Clicking on a visible row will make all rows with a class matching its id visible. Cli ...

Filtering data in an antd table by searching

Just starting out with React hooks, specifically using TypeScript, and I'm struggling to implement a search filter with two parameters. Currently, the search filter is only working with one parameter which is 'receiver?.name?'. However, I wo ...

How about trying out some dropdowns?

Following the issue I mentioned in my previous question titled Margin-Right on CSS not working, I am currently engaged in a creative endeavor to redesign my school's website homepage. The progress so far has been significant, but I now require some as ...

Can PhoneGap be used to create HTML5 applications from scratch?

Despite diligently searching through the PhoneGap website and their support group, I am still coming up empty-handed in my quest for an answer: My current project involves creating an application that functions as a pure HTML5 application, capable of runn ...

Include an HTML attribute within a given string

Using jQuery, I am adding HTML content to a div. The variables rowString and inputString have been defined beforehand: $("#filterContainer").append( rowString + `<label class='filterLabel' for=${filter}>${filter}< ...

Browsing the website through http://localhost instead of file:// while utilizing node.js

I am currently in the process of familiarizing myself with node.js. Everything appears to be running smoothly when I access the site from file:///C:/.../myfolder/index.html. The jquery and bootstrap files are located in the directories myfolder/css/ and m ...

Integrating image transitions into JavaScript

Could you provide guidance on how to create buttons from the three images within the "fadein" div in order to navigate directly to a specific jpeg? Currently, the three jpgs are displayed in a continuous loop. Thank you. ...

Obtain the attribute value from an HTML option element

Here is the code snippet I am working with: <select class="form-control valid"> <option isday="False" value="2">Value 1</option> <option isday="True" value="3">Value 2</option> <option isday="True" value="4"> ...

HTML - Using Tables to Add and Edit Rows

Take a look at this demo on JSFiddle for my project: Demo jsfiddle I'm currently in the process of creating a table with various functionalities. The function "sortTable" is responsible for sorting the table and it's functioning as expected. T ...

Utilizing Sass variables and customizing CSS styles within the main stylesheet

Hey there! I'm new to sass and I have a specific question about it. Do I need to link the scss file to a separate css file where I'm working, or can I write my styles directly in the same file? I tried using sass variables from Bootstrap 5.3.2, b ...