Reorder Flexbox items in Bootstrap 4 to display from top to bottom and left to right

Currently, I am utilizing Bootstrap 4 in conjunction with flexbox. Within a container-fluid, I have an alphabetically ordered list of items with the classes

col-xs-12 col-sm-6 col-md-4 col-xl-3
. These columns are responsive and as the number of items is variable, the height of the container cannot be predetermined.

The layout can consist of either 1, 2, 3, or 4 columns, and all rows have been designed to be consistently equal in width.

If you would like to see a demonstration of this setup, please visit: https://codepen.io/troutr/pen/XKQYjV

I have also provided an image showcasing the desired order: https://i.sstatic.net/aUmj6.jpg

Considering user experience, it would be beneficial if the items were organized top-to-bottom, left-to-right. Is there a way to achieve this using CSS? My initial thoughts revolve around utilizing media queries and the order property within flexbox.

Answer №1

Give the CSS property column-count a try. Be sure to check for browser compatibility here.

ul,
li {
  margin: 0;
  padding: 0;
  list-style: none;
}
ul {
  -webkit-column-count: 3;
  -moz-column-count: 3;
  column-count: 3;
}
<ul>
  <li>1</li>
  <li>2</li>
  <li>3</li>
  <li>4</li>
  <li>5</li>
  <li>6</li>
  <li>7</li>
</ul>
<hr>
<ul>
  <li>1</li>
  <li>2</li>
  <li>3</li>
  <li>4</li>
  <li>5</li>
  <li>6</li>
  <li>7</li>
  <li>8</li>
  <li>9</li>
  <li>10</li>
  <li>11</li>
  <li>12</li>
</ul>

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 is the best way to eliminate redundant template inheritance in Jinja2 for both Mobile and Desktop platforms?

Challenge In my code, I currently have navigation set up only for mobile devices. I am looking to eliminate the redundant template inheritance in Mobile (sm) and Desktop (md lg). The {% block main_content %}{% endblock %} code below is duplicated and inc ...

What is the most efficient way to retrieve the two smallest numbers using jQuery?

I am trying to find the two smallest numbers out of a set of three, and then I want to display them on the screen. In PHP, we usually use echo to display values on the screen. However, with this code snippet, I am only able to get one smallest value instea ...

Arranging text within a button in perfect alignment

Trying to create buttons with icons positioned on the left side, I stumbled upon a useful example online. However, no matter how much I tweak the code, I can't seem to get the text inside the buttons to align vertically. Working within Bootstrap 4 fra ...

Ways to conceal text as a div moves over it during hover effects?

How can I hide the title when hovering over the first child in my preview div items? I want to change the opacity of the title to zero on hover. Is there a simple way to achieve this effect? Currently, the layout looks like this - <div className="col ...

Adding the <br> tag in a Bootstrap modal: a simple guide

Hi everyone! I am currently working with a bootstrap modal to create a login functionality within the modal itself. There is a data validation function in place. However, when an error occurs, the word 'br' displays directly in the HTML instead ...

Content missing after centered banner

Seeking help! I need to figure out how to center text after a container. Whenever I try, it ends up either behind the banner picture or misaligned. I want both the banner and the text example to be centered, but placing the text in the right position has b ...

Extracting table data using regular expressions in Import.io is a powerful method to retrieve specific values

Need some assistance. I am currently utilizing import.io and aiming to extract table data using regex. My goal is to retrieve values from specific columns, below is the code snippet: <table> <tr> <td class='label&apos ...

What is the best way to center a parent container vertically?

I currently have a main grid with grid items that are also containers, set as inline-sized containers to allow for different internal layouts based on their width. How can I horizontally align the main grid in the center once it exceeds a certain width? A ...

The mobile CSS fails to adjust properly when I rotate the screen to landscape mode

In my code, I have styled the style.css file for mobile devices. The code works perfectly for mobile portrait size, but when I rotate the device to landscape mode, it calls the default CSS. How can I resolve this issue? @media only screen and (min-de ...

Struggling with getting the Encore Webpack Bootstrap4.5 navbar to function properly

I am currently diving into the world of Symfony, and I have chosen to leverage bootstrap for styling my page. Interestingly, when I include the link, <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_ema ...

What should I do to resolve the issue of the function if ($(window).width() < 768) {} not functioning properly upon resizing the browser?

I am working on a functionality where the navigation bar items will toggle hidden or shown only when the browser width is less than 768px and an element with the class "navlogo" is clicked. I have included my code below for reference. if ($(window).width( ...

What guidelines should I establish for arranging 2 rows of .col?

I'm currently working on setting up two rows of .column elements in my HTML document. Right now, I have one row of columns followed by another row in the footer. While the first row of columns is behaving as expected, the second row aligns vertically ...

Error parsing XML: Missing opening tag

function fetchUserDetails() { $url = "http://steamcommunity.com/profiles/{$this->steamID64}/?xml=1"; $xmlData = simplexml_load_string($url); if(!empty($xmlData->error)) { return NULL; } $this->displayName = (string) $xmlData-&g ...

Electron framework experiencing compatibility issues with JQuery

I am currently attempting to integrate jQuery with the electron framework using electron fiddle. However, it seems that jQuery is not functioning correctly and animations are not being executed. For reference, you can check out the example: https://www.w3s ...

The span's presence causes the neighboring span to shift downwards

HTML <span class="symbol">$</span> <span class="value">400</span> This code snippet displays the symbols "$" and "400" at the same level in the document. However, if we introduce some styling using CSS: .symbol { font-size: 2e ...

What is the best way to stop a jQuery event listener on a button within a form from triggering upon the user hitting the Enter key?

Here is an example of a form containing a button: <form> <input type="text"> <button>Click Me</button> <input type="submit" value="Submit"/> </form> Using the following JavaScript: $('form').subm ...

Having trouble selecting elements that have been dynamically generated through an Ajax callback function

During an AJAX callback, I am trying to insert a DIV with a unique ID into another specific DIV called A. However, after each call, if the div with the given id is not found as a child element of DIV A, a new DIV is created and appended. Strangely, every t ...

The functionality of Bootstrap 4's Responsiveness seems to be malfunctioning

CSS Framework: Bootstrap 4 JQUERY, JS MASK for validation and input masking Custom CSS used for styling elements including coloring, margins, padding, and font sizing Optimized for Desktop and Laptop screen sizes Not fully responsive on Mobile, Tablet, ...

Display picture next to content with the help of CSS/Bootstrap and Django's Jinja 2

I'm having trouble displaying an image next to text, it keeps showing up below. Here's the code snippet: <div class="container"> <div class="row"> <div class="col-md-8"> < ...

Integrating a fictitious style using jQuery

Having some trouble with this code snippet. The issue arises when trying to apply the following style using jQuery. CSS .arrow_box { position: absolute; width: 24px; border-radius: 30px 30px 3px 3px; height: 17px; float:left; } .arrow_box:after { bord ...