Troubleshooting problem with CSS aligning <dl> and <dd> tags

Utilizing <dt> and <dd> typically assumes a single line definition for dd. However, in my scenario, I have multiple entries for the definition that I need to correctly display (the exact method will be clarified after reviewing the attached image). Therefore, I am employing <da> which has been styled with CSS (margin: 0 0 0 21.3%) to attain the desired style below. Nonetheless, I am encountering the following issues:

  1. A line appears above the first entry (i.e., Mr. A ?).
  2. Testing on monitors of different sizes results in shifted alignment. For instance, on a smaller monitor, using margin: 0 0 0 22.3% works!)
  3. When zooming in and out, the alignment shifts. (Zooming in shifts left, zooming out shifts right)

Current State

Desired Outcome

Given that I have implemented the design using <dt> and <dd> across several pages, it would be beneficial to find a solution within this framework.

.top-class-name {
margin-left: 25px;
background-color: white;
padding: 0.5ex;
width: 75%;
}

.top-class-name > div {
margin-bottom: 1em;
}

.top-class-name dl {
margin: 0;
}

dl {
display: block;
-webkit-margin-before: 1em;
-webkit-margin-after: 1em;
-webkit-margin-start: 0px;
-webkit-margin-end: 0px;
}

.top-class-name dt{
display: inline-block;
vertical-align: top;
width: 220px;
}

.top-class-name dd {
display: inline-block;
vertical-align: top;
margin: 0;
width: 73%;
}

dd {
display: block;
-webkit-margin-start: 40px;
}

.top-class-name dd:after {
content: '\A';
white-space: pre;
}

.top-class-name da{
display: block;
vertical-align: middle;
margin: 0 0 0 21.3%;
width: 43%;
}
<div class="top-class-name">
    <div>
        <dl>
            <dt>Other Term :</dt>
            <dd>xxxxxxxxxxxxxxxxxxxxxxxxxx</dd>
            <dt>Other Term :</dt>
            <dd>xxxxxxxxxxxxxxxxxxxxxxxxxx</dd>
            <dt>Guest Names :</dt>
            <da>Mr. A</da>
            <da>Mr. B</da>
            <da>Mr. Z</da>
            <dt>Other Term :</dt>
            <dd>xxxxxxxxxxxxxxxxxxxxxxxxxx</dd>
            <dt>Other Term :</dt>
            <dd>xxxxxxxxxxxxxxxxxxxxxxxxxx</dd>
        </dl>
    </div>    
</div>

Answer №1

If you're looking to organize the listed items neatly, one approach is to group them inside a container (like a ul) and float the dt. To ensure everything stays in place, be sure to include overflow:auto on the container to create a new block formatting context.

I made some adjustments to your CSS code, focusing on the key concepts needed for this arrangement. The use of floated elements and the overflow property should provide the functionality you're after.

.top-class-name {
margin-left: 25px;
background-color: white;
padding: 0.5ex;
width: 75%;
}


.top-class-name > div {
margin-bottom: 1em;
}

.top-class-name dl {
margin: 0;
}

dl {
display: block;
-webkit-margin-before: 1em;
-webkit-margin-after: 1em;
-webkit-margin-start: 0px;
-webkit-margin-end: 0px;
}

.top-class-name dt{
display: inline-block;
vertical-align: top;
width: 220px;
}

.top-class-name dd {
vertical-align: top;
margin: 0;
}

dd {
display: block;
-webkit-margin-start: 40px;
}

.top-class-name da{
display: block;
vertical-align: middle;
margin: 0 0 0 21.3%;
width: 43%;
}

dt {
  float:left;
  clear:left;
}

dd ul {
  margin: 0;
  padding: 0;
  list-style-type: none;
  overflow: auto;
}
<div class="top-class-name">
    <div>
        <dl>
            <dt>Other Term :</dt>
            <dd>xxxxxxxxxxxxxxxxxxxxxxxxxx</dd>
            <dt>Other Term :</dt>
            <dd>xxxxxxxxxxxxxxxxxxxxxxxxxx</dd>
            <dt>Guest Names :</dt>
            <dd>
                <ul>
                    <li>Mr. A</li>
                    <li>Mr. B</li>
                    <li>Mr. Z</li>
                </ul>
            </dd>
            <dt>Other Term :</dt>
            <dd>xxxxxxxxxxxxxxxxxxxxxxxxxx</dd>
            <dt>Other Term :</dt>
            <dd>xxxxxxxxxxxxxxxxxxxxxxxxxx</dd>
        </dl>
    </div>    
</div>

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

Trouble with FilterBy Feature in Bootstrap-Table

I am attempting to use filtering functionality with a table that is populated via JSON, utilizing bootstrap-table by wenzhixin. HTML snippet: <button class="btn btn-primary" id="filterBtn">Filter</button> <div class="container"> &l ...

Displaying a limited number of items from a large JSON Array in an HTML unordered list, showcasing only 20 data entries per

My JSON file has a specific format that includes key-value pairs for data entries. There are hundreds of these entries. I am currently working on: a. Loading these values onto an HTML page. b. Displaying only the first 20 entries. Below is the code snip ...

Is there a glitch in the Bootstrap v4 Navbar?

Encountering an issue with the default navbar example from Bootstrap's official website. The navbar is supposed to be full-sized and collapse when the screen size decreases. However, after implementing the code into my project, it appears as always co ...

How to send varying URL parameters to AJAX function within Django applications

Can anyone assist with passing different URL names to a javascript function? Below is the HTML and Javascript code I am using: {% for profile, g_name in group_list %} <li class="contact"> <div class="wrap"> ...

Is there a way to stop ng-repeat in AngularJS 1.2 from encoding or escaping my content, or do I have to create my own directive for this?

Is there a way to stop ng-repeat in AngularJS 1.2 from encoding or escaping my content without creating a custom directive? I know that ng-bind-html-unsafe is no longer supported in Angular 1.2, but I'm unsure about its compatibility with ng-repeat. S ...

Displaying selected list item while concealing the original

I have a dropdown menu with several options. What I am looking for is to have it so that when we click on the drop down, a list of choices appears. Then, when we select an option from the dropdown, the original selection should be replaced with the one th ...

Utilizing Multiple Select Options and CSS Float Styling in Mozilla Firefox

I have been attempting to customize the CSS of a multiple select element. While I am satisfied with how it looks on Chrome, I am facing issues getting it to work correctly on Mozilla Firefox. $('option').mousedown(function(e) { ...

Personalizing HTML input fields

I am looking to create a contact form that will display an image depending on whether the input entered is correct or incorrect. My goal is to achieve this using only HTML and CSS, without needing any JavaScript. While there are similar posts on this topic ...

Choose the section of the date input that represents the day

Is there a way to focus an HTML input element with type="date" and select only the day part of the date? I attempted: $("#entry-date-text").focus(); var dt = $("#entry-date-text")[0]; dt.setSelectionRange(3, 5); However, this resulted in the following e ...

Angular 2's Multi-select dropdown feature allows users to select multiple options

Recently, I encountered an issue with customizing CSS for angular2-multiselect-dropdown. I found the solution in this link: https://www.npmjs.com/package/angular2-multiselect-dropdown. I have included my code below. Any assistance in resolving this matter ...

What could be causing my PHP code to not execute properly alongside the HTML?

I am currently sharpening my skills in PHP by working on a simple web form project. To put it simply, I need to develop a basic web form that accepts a two-dimensional array of European cities along with the distance in kilometers between each pair of citi ...

Refresh the HTML content within a specified div element

In my index.html, there is a graph (created using d3.js) along with some code that displays a stepper with a number of steps equal to the child nodes of the clicked node: <div ng-include="ctrl.numlab==2 && 'views/stepper-two-labs.htm ...

The functionality of a pop-up window is not compatible with Google Maps

I recently implemented a script on my webpage that triggers a popup window every time the page is loaded. Here's how the script looks: <!DOCTYPE html> <html> <head> <meta charset=utf-8 /> <title>ColorBox de ...

I successfully created an animation with jQuery for an image, but unfortunately, it seems to malfunction during the second

$( "#btn1" ).click(function() { var $this = $(this); var clickCount = ($this.data("click-count") || 0) + 1; $this.data("click-count", clickCount); if (clickCount%2 == 0) { $("#img1").hide('clip').animate({ margi ...

Browser unresponsiveness triggered by excessive Ajax setInterval functionality

Here is the test code I am currently using: <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Ajax - one variable test</title> <style> body{ font-size: 12px; font-family: Arial;} </styl ...

The setInterval function for the automated image slider is experiencing issues and is not functioning properly

I am facing an issue where the third photo in the slider does not appear initially. Eventually, the slide fails completely, causing the photos to change rapidly. Strangely, after the slide fails, the third photo sometimes appears sporadically. I am puzzl ...

Struggling with the toggle functionality in the Boostrap Nav Bar?

My bootstrap navbar is not functioning properly when I switch to mobile size and click the expand button. Could this issue be due to using the wrong classes for bootstrap 5 instead of bootstrap 4? <nav class="navpaddingy navbar navbar-expand-lg ...

Encountering an issue when attempting to store image links in the database using PDO

One idea that I have is to create an image uploader system that sends the image to the 'upload' folder and saves the link to the database. I encountered errors in my 'images.php' file. Can anyone assist me with resolving these issues? ...

How can I use jQuery to check a checkbox without triggering its bound event?

I've created a custom checkbox that will log its value to the console, and I'm trying to add a button that can tick the checkbox without triggering the checkbox event. This is purely for educational purposes. $(document).on('click', ...

Utilizing the power of SimpleHTMLDom to retrieve high-resolution images through an advanced Google search

I want to display a large image that was retrieved from Google using simple_html_dom.php include_once( "simple_html_dom.php" ); $key="unique"; $html = new simple_html_dom(); $html=file_get_html('http://images.google.com/images?as ...