When utilizing "column-count" with "display: flex", both Firefox and IE will only render a single column

I am struggling to achieve a two-column layout with nested columns inside each one. The code I used looks great on Chrome and Safari, but on Firefox and IE, it only displays in a single column:

What mistake am I making here?

.two-columns {
  column-count: 2;
  dt,
  dd {
    break-inside: avoid;
    column-break-inside: avoid;
  }
}

dl.name-value {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  dt {
    padding-right: 0.5rem;
    width: 40%;
    text-align: right;
  }
  dd {
    width: 60%;
    margin-left: auto;
  }
}
<div class="two-columns">
  <dl class="name–value">
    <dt>Milkman</dt>
    <dd>A man with a milk</dd>
    <dt>Postman</dt>
    <dd>A man with a post</dd>
    <dt>Manila</dt>
    <dd>A man with ila</dd>
    <dt>Layman</dt>
    <dd>A husband</dd>
  </dl>
</div>

Edit – apologies for the hyphen confusion :(

The reason behind using column-count is that I do not know in advance how many key-value pairs I will have. It could be two, six, or eight, but I still want them displayed in two neat columns. Check out the desired layout image here: https://i.sstatic.net/AACDf.png

Answer №1

Upon initial inspection, I immediately noticed that your CSS dl.name-value selector was not aligning with the HTML <dl class="name-value"> element. This discrepancy in styling was consistent across various browser inspectors, where the CSS code failed to display.

https://i.sstatic.net/SxWhA.png

After checking for any issues with quotation marks and verifying their correctness, I explored potential problems stemming from SCSS, HTML Definition Lists (<dl>), CSS specificity, and combinations thereof. However, no conclusive findings emerged, even when running the code without SCSS implementation.

I also investigated whether there could be compatibility concerns between using display: flex within a Multi-Column Layout. Yet, it became evident that none of the declarations were matching up. For instance, discrepancies arose when applying background-color:

.two-columns {
  column-count: 2;
}

dl.name-value {
  background-color: green;
  height: 500px;
  /* display: flex;
  flex-wrap: wrap;
  justify-content: space-between;   */
}

dt {
  padding-right: 0.5rem;
  width: 40%;
  text-align: right;
}

dd {
  width: 60%;
  margin-left: auto;

}

dt,
dd {
  break-inside: avoid;
  column-break-inside: avoid;
}
<div class="two-columns">
  <dl class="name–value">
    <dt>Milkman</dt>
    <dd>A man with a milk</dd>
    <dt>Postman</dt>
    <dd>A man with a post</dd>
    <dt>Manila</dt>
    <dd>A man with ila</dd>
    <dt>Layman</dt>
    <dd>A husband</dd>
  </dl>
</div>

Further analysis revealed that the culprit causing the issue was the hyphen (-). The hyphen utilized in the HTML differed from the one employed in the CSS file once scrutinized at each character level.

.two-columns {
  column-count: 2;
}

dl.name-value { /* hyphen (keyboard minus sign) now matches HTML class value */
  background-color: green;
  height: 500px;
  /* display: flex;
  flex-wrap: wrap;
  justify-content: space-between; */
}

dt {
  padding-right: 0.5rem;
  width: 40%;
  text-align: right;
}

dd {
  width: 60%;
  margin-left: auto;

}

dt,
dd {
  break-inside: avoid;
  column-break-inside: avoid;
}
<div class="two-columns">
  <dl class="name-value"><!-- hyphen (keyboard minus sign) now matches CSS selector -->
    <dt>Milkman</dt>
    <dd>A man with a milk</dd>
    <dt>Postman</dt>
    <dd>A man with a post</dd>
    <dt>Manila</dt>
    <dd>A man with ila</dd>
    <dt>Layman</dt>
    <dd>A husband</dd>
  </dl>
</div>

While this adjustment may provide a resolution, it underlines the varying rendering outputs observed across major browsers when employing a flex container within a multi-column box. To explore more tailored solutions, sharing additional details about your desired layout will assist in determining whether utilizing column-count, flex, or grid layouts is ideal.

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

Creating a horizontal scrollbar in columns using Bootstrap can be accomplished by adjusting the CSS properties

Having a container created with boostrap: https://i.sstatic.net/bqAuf.png The question at hand is how to implement horizontal scrolling in order to maintain the aspect ratio of the initial image within the container on phone resolutions. Here is the con ...

Specify the location of the resize button (corner)

Scenario : At the bottom of the page, there is a resizable textarea, However, having the resize button at the bottom-right corner does not provide the best user experience (try it out), Issue : I am wondering if there is a way to move the resize butt ...

What is the correct way to apply background-position percentage in this situation?

This problem has got me at my wit's end. Imagine a series of divs lined up horizontally. Each one is sized as a percentage of the total width, but that total width is unknown. For instance: --------------------------------- | | | ...

Styles applied in the child component will have a cascading effect on the entire webpage

My webpage is divided into two parts: child1 and child2. Page Hierarchy: Parent Child1 Child2 Here are the CSS styles included in the page: Child1 -> z-index: 1 Child2 -> z-index: 2 What I want to achieve is to add a backdrop to the entire ...

Display Page Separation with JavaScript

I am working on a project where I have created payslips using Bootstrap through PHP. To maintain organization, I am looking to create a new page after every 6 payslips. Below is the code snippet that I am using to generate the payslips: foreach($results a ...

What is the best way to implement padding for two DIVS on a screen utilizing VH and VW units to ensure they fill up the

I am currently working on a layout with two columns spanning across the page. I need to add some padding around the text in each column so that it sits nicely in the middle. I have been trying to adjust the div width and use wrappers, but something seems t ...

Two columns of equal height featuring three card UI elements

I'm currently working with Bootstrap 4 and I have a grid set up with 1 row containing 2 columns and 3 card elements. However, I am struggling to adjust the height of the blue card element to align with the yellow card element. I want both cards to ha ...

Modify the table layout by incorporating images within separate div containers for each row

In my layout, there is a grey box element that contains a table with rows of small images. I want the table to automatically adjust based on the number of images so that when the grey box reaches its maximum size, the images move to the next row. Is this a ...

Mysterious JQuery attribute

I've come across a piece of code that utilizes an unfamiliar selector that I can't seem to figure out: $("div[tag=" + someVariable + "]").css("display", "block"); From what I gather, the selector is searching for a div element with an attribute ...

Adjust the background color of a non-selected Material-UI checkbox

Currently, I am working with a combination of React-Redux and Material-UI to style my project. Within this setup, I have a checkbox component that is placed on a toolbar with a blue background color (#295ED9). So far, I have successfully altered the color ...

Problem arises with table nth-child selector following the addition of grid-gap

Our current table looks like this: The first row has a background color and the second row is white - which is correct. Now I would like to align the attributes to the right. I added the following code to the table: .table-wrapper tbody { font-size: ...

Uploading files with previews and no option to alter the image dimensions

I am having trouble with resizing an image preview before submitting it. Despite setting the width and height to 1px in both the div and image, it still displays at its normal dimensions. $(function() { var imagesPreview = function(input, placeToIns ...

Choose a Range of DOM Elements

My challenge is to select a range of DOM elements, starting from element until element. This can be done in jQuery like this: (Source) $('#id').nextUntil('#id2').andSelf().add('#id2') I want to achieve the same using JavaScr ...

Flexbox does not support sub-columns

I'm having trouble integrating these two columns along with their sub-columns. I have to resort to using this structure instead: <div class="custom_classes"> <div class="custom_classes">col1</div> <div class=&q ...

Is gulp.dest set to match the current file?

I'm having trouble directing my compiled .css file to the same directory as its original .scss version. gulp.task('sass', function() { return gulp.src([ appDir + '/*.scss', appDir + '/**/*. ...

Center JQuery within the current screen

My implementation of Jquery dialog is as follows: <body> <div id="comments_dialog"> Insert a comment <form> <input type="text" id="search" name="q"> </form> </div> .... </body> dialog = $( "#com ...

Troubleshooting the Confirm Form Resubmission problem on my website

Hello everyone! I'm working on a website and facing an issue where refreshing the page triggers a confirm form resubmission prompt. Could someone please advise me on how to resolve this? Thank you in advance! ...

Customize the website's CSS for optimal viewing on an iPad

I have a website with two CSS files: one for viewing the site on a desktop screen and the other for viewing it on an iPad screen. Despite having the same HTML code, is there a way to detect the iPad device and force it to use the appropriate CSS file? Tha ...

Struggling with the Nivo slider not loading properly?

Check out my personal website. I'm having an issue with my Nivo slider not displaying properly - it just keeps loading. Any ideas on why this is happening and how I can fix it? Below is the CSS I am using: #slider { position:relative; width: ...

Appear and disappear gradually when hovering

When hovering over #one, the class .hidden is applied to #first. I have added a script to make .hidden fade out using transition: ease-in 0.3s;, but I am having trouble getting the fade in effect to work. I attempted adding transition: ease-in 0.3s; to #fi ...