List of descriptions: One pair per line

In need of a solution to align the term and description in a description list on the same line.

The current code I have works, but it doesn't look very professional. It's time to update it with a more modern approach using flexbox. But how can I implement flexbox for this?

dt, dd { float: left; }
dt { clear: both; font-weight: bold; }
dd { margin-inline-start: 1em; } /* Ideally avoid changing browser defaults */
<dl>
  <dt>Coffee</dt>
  <dd>Black hot drink</dd>
  <dt>Milk</dt>
  <dd>White cold drink</dd>
</dl>

Answer №1

Utilizing display: flex for dl enables you to leverage CSS flexbox. For a more polished look, consider incorporating color, padding, and various text formatting styles.

dl {
  display: flex;
  flex-wrap: wrap;
  /*adjust width, font-family, and margin based on your needs*/
  max-width: 400px;
  margin: 0 auto;
  font-family: helvetica, arial, sans-serif
}

dt,
dd {
  width: 50%;
  padding: 10px;
  box-sizing: border-box;
  margin: 0;
}

dt {
  font-weight: 700;
  background: #ddd;
  border: 1px solid #ccc;
}

dd {
  background: #f2f2f2;
  border: 1px solid #ccc;
}
<dl>
  <dt>Coffee</dt>
  <dd>Black hot drink</dd>
  <dt>Milk</dt>
  <dd>White cold drink</dd>
</dl>

Answer №2

Simply put, I would use the display: flex; property on the parent dl element to control its child elements and style them like this:

dl {
    display: flex;
    flex-flow: row wrap;
}
dt, dd {
    width: 50%;
}

This code essentially instructs flexbox to arrange items horizontally in a row and wrap them to the next line if they exceed the width of the dl container.

By setting the dt, dd elements to be 50% of the total wrapper width, we ensure that only two elements are displayed in each line at most.

If you want to dive deeper into the concept, you can check out CSS-Tricks for a detailed guide on using flexbox layouts effectively.

Answer №3

If you're looking to implement flex in your code, it may be necessary to make some structural changes. Check out this comprehensive resource for everything you need to know about flexbox -> A Complete Guide to Flexbox

In regards to your comment

Your current approach seems outdated and unprofessional

I recommend exploring alternative font styling options instead of using dt and dl, as they are quite antiquated

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

Displaying text and concealing image when hovering over a column in an angular2 table

I am currently using a table to showcase a series of items for my data. Each data entry includes an action column with images. I would like to implement a feature where hovering over an image hides the image and reveals text, and vice versa (showing the im ...

Continue scrolling the HTML page before it reaches the end

https://i.sstatic.net/6iBof.png I am currently troubleshooting an issue with my chat thread. At the moment, the chat window automatically scrolls up when it reaches the bottom of the page to ensure it is always visible. However, there is a problem where ...

Converting HTML to PDF using AngularJS

Can anyone help me with converting HTML to PDF in Angular? I have tried using the angular-save-html-to-pdf package from npm, but encountered errors. Are there any other solutions or custom directives available for this task? ...

positioning a div based on the location of another div

I am currently working on aligning a div that sits at the bottom of all other divs. The last div is set to float and aligned at the top using CSS. I am unsure how to align it from the left side without any issues when the screen resolution changes. Is th ...

When the mouse is moved to the UL LI list, the border color of the Top Hover is reverted back to default

Can you assist me with this issue? I need to modify the code below so that the border color remains blue while a user selects an item from the UL LI list. Here is an image showing the current problem: https://i.sstatic.net/DS7hO.png And here is a pictu ...

different approach for hiding content on mobile devices

Currently in the process of developing a responsive website for practice. I am utilizing Twitter Bootstrap JS and CSS to enhance an existing website, ensuring it is fully optimized for mobile devices. One challenge I am facing is dealing with large carous ...

How can you reset the chosen option in a Vue.js dropdown menu?

Within my dropdown menu, I have included a button that is intended to clear the selected city. Despite adding an event, the selected option is not being cleared. Can anyone provide insights on what I might be missing? Thank you in advance. Below is the bu ...

Is it possible to add additional text to an input field without modifying its existing value?

I have a numerical input field labeled "days" that I want to add the text " days" to without altering the actual numerical value displayed. <input type="number" class="days" (keyup)="valueChanged($event)"/> Users should only be able to edit the num ...

Using HTML, CSS, and jQuery to create step-based scrollbar navigation

My current setup includes a horizontal scrollbar with products displayed inside. However, when I scroll to the right and then back, I can only see half of a product at a time. Is there a way to implement scrolling in increments of 200px using HTML/CSS/jQue ...

What could be causing the JavaScript on my website to not function properly?

I've encountered an issue with the script on my website. Despite double-checking everything and following a tutorial closely, it still doesn't seem to work. Any suggestions or ideas? Here are the links to my GitHub repository and a preview of th ...

It seems that in Laravel 5.3, it's challenging to add a script to a view for an autocomplete

Currently, I am working with Laravel 5.3 for my internship. However, I have encountered a frustrating issue that I need help with: I am trying to implement an "autocomplete" field on a page, but it doesn't seem to be functioning correctly. The error ...

Toggle the field on and off using HTML and JavaScript from the bottom

My goal is to enable two fields in a row by clicking on "activate1", while the other fields remain unchanged. Similarly, I want to activate the other two fields by using "activator2" and so on. There should be three activators at the bottom solely for acti ...

Attempting to squeeze a container with a set width into a parent element that spans the entire width of the screen (100

As I embark on my coding journey, I am faced with the challenge of creating a website that features full-width (100%) containers with fixed-width containers nested inside. Despite my efforts to experiment with both figures and divs, I have not been success ...

Stop and resume CSS animation when the user hovers over and leaves

Can you share some insights on how to pause and resume a CSS transition? Check out the code below: animationstate = "running"; function animate() { if (animationstate == "running") { deskppssystemdiv.style.transitionDuration = "2000ms"; ...

The div keeps appearing multiple times while the button remains inactive

In order to create a password confirmation form with validation, you need to have two input fields - one for entering a new password and another to confirm the password. The goal is to display a message saying "please enter the password above" below the ...

Move the check mark to the middle of the screen

I am a beginner in HTML and I am trying to create a logout page that should have a design similar to this: https://i.sstatic.net/ld1R1.png I attempted to create it but I am struggling to position the icon correctly and I also want the whole content to be ...

What are the steps to storing numerical inputs as variables using jQuery and then using them to perform calculations in order to update the input numbers

Currently, I am in the process of creating a BMI calculator using HTML and jQuery. <form id="bmiCalculator"> <fieldset> <legend>BMI Calculator:</legend> <p> <label>Height: ...

How to transform text into clickable links using AngularJS

Is there a way to make text URLs clickable? I have been using angular-sanitize.min.js version 1.2.11 since my first deployment. angular-sanitize works well for URLs that start with http/https/ftp/email but not for www. I need the following text URLs to b ...

AngularJS button within a Bootstrap navbar

I'm a fan of the current navigation bar style in Twitter Bootstrap v3.3.6 and I'm curious about how to integrate AngularJS buttons into it. <nav class="navbar navbar-default"> <div class="container"> <div ...

How to render a div in HTML with full CSS styling applied

I'm currently working on a project using asp.net MVC. My goal is to print a div with all the CSS styles applied, which may contain one or more nested divs. Despite trying various JavaScript print codes, I have not been successful. The page I want to p ...