Organizing an Ordered List of Items into Alternating Columns Using HTML

I am in the process of developing a responsive HTML design to showcase an array of organized data.

For smaller screens, the layout will consist of a single column displaying items sequentially. However, on larger screens, the design should adapt to feature two columns with items alternating between them.

Example for Small Screens

| 1 |
| 2 |
| 3 |
| 4 |

Example for Large Screens

| 1 | 2 |
| 3 | 4 |

In the two-column layout, elements in the left column should be styled with float: right, while those in the right column should have float: left. This arrangement ensures that the items align at the center, regardless of their width.

One approach I've considered is creating two separate column containers – one for elements floated right and another for those floated left. However, I still need to figure out how to distribute the ordered array items effectively without splitting them into two groups. Dividing them this way would disrupt the sequential order when transitioning to a smaller screen size.


Edit 1: Not all elements may have the same height. When positioning an element, it should fit into the row with the least total height.

|    ------|----------|
|    |  1  |     2    |
|    |     |----------|
|    |     |   3   |  |
|    ------|-------   |

This jsfiddle provides a rough prototype of what I am aiming to accomplish, albeit in a less cumbersome manner. The layout I aspire to achieve resembles something like this, however, maintaining the specific ordering of elements.

Answer №1

After conducting experiments, my friend and I concluded that the most effective approach was to implement display: flex on left elements, paired with float: right on the right elements. You can view an example of this implementation in action on this jsfiddle link.

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

Converting data in MongoDB arrays

As a beginner with MongoDB, I am attempting to transform the data within each document using the provided information. Any assistance in completing this task would be greatly appreciated. getconvaggregate1 collection:(existing) { "_id&qu ...

Modifying array elements in JavaScript without explicit instructions

I am relatively new to Javascript and seem to be encountering a rather puzzling issue that I'm unable to resolve. Currently, I have two classes: Country and PPM_Data. The Country class contains parameters such as name, area, ppm, etc., along with a f ...

Generate hyperlinks in HTML with PHP by utilizing XML

I am looking to create links for my website based on an XML document structure. Here is an example: <menu> <item> <name>Menu Item One</name> <itemurl>folder\location\page.php</itemurl> <captio ...

Tips for Editing an HTML File

As a beginner in the world of coding, I am currently working on creating a quiz maker. My question is how can I use code to edit a file? For example, if a user inputs a question name, how can the code automatically update the corresponding question in th ...

Is there a way to configure the positioning of Bootstrap carousel thumbnails to be above and beside?

My goal is to customize a bootstrap 5 thumbnails carousel by placing the thumbnails either on the top or the left side of the slides section. The default setting is at the bottom, but I need these two variations. The base model works perfectly, but I' ...

Strategies for avoiding the opening of a new tab when clicking on a link in ReactJs

RenderByTenantFunc({ wp: () => ( <Tooltip id="tooltip-fab" title="Home"> <Button className="home-button"> <a href={ ...

Toggle the backgroundImage visibility by setting it to either hidden or displayed using jquery

$('.arrow').css("background-image", "url('../img/arrow.png')").hide(); I have implemented a custom solution using CSS and jQuery to hide the downward arrow when scrolling down on my webpage. `$( document ).ready(function() {
 co ...

Is it possible to create an index.html page with all the necessary head tags to prevent duplicate code across multiple html pages?

Imagine I am using app.js or a Bootstrap CDN link for all of my HTML pages, but I don't want to include it in every single page individually. Is there a way to create an index.html file that includes this so that all other HTML pages load the head fro ...

Incorporating local JSON data into HTML: A Step-by-Step

I'm completely new to javascript and the utilization of json. What I want to accomplish is quite straightforward, although I am encountering difficulties. My objective is to create a website consisting of two pages: one that showcases artists and ano ...

Maintaining aspect ratio in CSS grid layouts

I am in the process of designing a CSS grid layout where I want to maintain the same height for all columns. Additionally, I would like the first item to have a 16:9 aspect ratio. However, I am encountering an issue where the images are not fitting perfect ...

Unable to view Bootstrap Icons in Gulp 4

I recently integrated the new bootstrap icons npm package into my project using Gulp 4, the latest version. Everything was installed successfully and was working smoothly. However, I encountered an issue when trying to declare the icon in my index.html fi ...

Assistance needed in restructuring code to eliminate white space between Divs

I am looking to combine two divs in the header section of my website. Both divs should have a black background with no white space between them. Can anyone provide advice on this? Additionally, I would appreciate any recommendations on how to structure my ...

How come my Ajax call is setting the 'Content-Type' to 'application/x-www-form-urlencoded' instead of 'JSON' as specified in the dataType parameter?

I have encountered an issue while responding to a button click using the code snippet below. The console.log() confirms that the function is being called, but the HTTP request it generates contains the header "Content-Type: application/x-www-form-urlencode ...

Tips for creating an input field that automatically expands and has a specific width

I am facing an issue with the alignment of my search field. Here is the code snippet: #menu_search{ position: absolute; width: 100%; max-width: 1280px; display: inline; float: right; right: 0px; z-index: 99; } I would like th ...

Tips for applying CSS styles to the active page link

Check out the code below: Is there a way to assign a specific class to the current page link so that the mouse cursor will display as default rather than changing to a hand icon? I'm looking for a solution where I can apply a class to the active lis ...

position blocks next to each other within a container

Thank you for all the hard work! I've been struggling to figure out how to align blocks next to each other within a div. It may not be that difficult, but I just can't seem to find an elegant solution... Here is the HTML code snippet: <div ...

Searching for a specific text within an element using XPATH in C# with the Selenium framework

My current challenge involves locating specific text within certain elements on an HTML page. <a class="ProductCard-link ProductCard-content" target="_self" tabindex="0" href="/en/product/puma-future-rider-menshoes/314 ...

Is it possible to set a click event or <A> link on an entire Ember component?

One of my Ember components has a tagName:'li' This is how the template appears: <div> title</div> <div> image </div> <div> text </div> The result is <li> blocks consisting of the elements above, displ ...

Having trouble locating the CSS and JavaScript files within my Spring Maven project

I have a Spring framework application with a Maven project. In addition, I have CSS and JavaScript files under the WEB-INF folder. When attempting to link the JavaScript and CSS files like this: <link rel="stylesheet" href="../allDesign/js/vendor/anims ...

"Utilizing JavaScript, you can remove an element by clicking on the outer element within the

I need the functionality where, when a user clicks on an input type="checkbox", a corresponding textarea is displayed. Then, if the user clicks anywhere except for that specific textarea, it should be hidden. Can someone assist me with implementing this fe ...