Arrange divs in a float-stacked formation next to each other, without the need for a

I'm facing a challenge trying to display stacked divs in a column-like manner. Unfortunately, I can't directly edit the HTML due to the constraints of the application. The issue I'm encountering is that the right column is appearing lower down on the page instead of aligning with the top. Normally, I would enclose each section in a div and float or inline-block them to achieve the desired layout. However, using jQuery functions like .wrapAll() to add the necessary HTML directly to the document is not an option for me. Any assistance or recommended resources would be greatly appreciated. Thank you.

You can view an example of the code on this jsfiddle: https://jsfiddle.net/itivae/30xhjwcz/5/

    <style>
        .content-wrapper {
            position: relative;
            overflow: hidden;
        }
        .div-1, .div-2, .div-3, .div-4, .div-5 {
            float: left;
            width: 100%;
            max-width: 48%;
            clear: left;
            position: relative;
        }
        .div-6, .div-7, .div-8, .div-9, .div-10, .div-11, .div-12 {
            float: right;
            width: 100%;
            max-width: 48%;
            clear: right;
            position: relative;
        }
   </style>
   <div class="content-wrapper">
       <!--This is the left column-->
       <div class="div-1">Content</div>
       <div class="div-2">Content</div>
       <div class="div-3">Content</div>
       <div class="div-4">Content</div>
       <div class="div-5">Content</div>
       <!--End of left column-->
       <!--Start of right column-->
       <div class="div-6">Content</div>
       <div class="div-7">Content</div>
       <div class="div-8">Content</div>
       <div class="div-9">Content</div>
       <div class="div-10">Content</div>
       <div class="div-11">Content</div>
        <div class="div-12">Content</div>
        <!--End of right column-->
    </div>

Answer №1

The primary concern lies in the positioning of the wrapper class and the necessity for a width less than 100% on each side. Sometimes, a simpler approach can be more effective.

.content-wrapper {
  width: 100%;
  overflow: hidden;
}
.div-1, .div-2, .div-3, .div-4, .div-5 {
  float: left;
  width: 50%;
}
.div-6, .div-7, .div-8, .div-9, .div-10, .div-11, .div-12 {
  float: right;
  width: 50%;
}

https://jsfiddle.net/4ezcbkmo/

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

The difference between using an event listener directly in HTML vs. using the add

Looking to customize the behavior of an HTML element using event listeners? There are two ways to accomplish this: <form class="my-form"> <input type="submit"/> </form> <script> document.querySelectorAll(&quo ...

What is the best way to reveal and automatically scroll to a hidden div located at the bottom of a webpage?

Whenever the image is clicked, I want to display a hidden div with effects like automatically scrolling down to the bottom This is what my code looks like: $(document).ready(function() { $('#test').click(function() { $(&apos ...

The title attribute in Vue3 is updated through props, but computed properties remain unaffected

I incorporated an external library into my project using Vue3. The component I am utilizing is sourced from a third-party library [Edit: Upon realizing that the GitHub repository for this library is no longer being maintained, I have updated the code to re ...

The jQuery prop method seems to be malfunctioning

Here is the HTML code snippet: <ul class="expander-list" id="category"> <li> <div class="radio" style="padding-left:0px"> <label> <input type="checkbox" id="all" ...

PHP MySQL Form EditingWould you like to edit forms

Hi, I'm facing an issue with my edit form and despite trying to solve it, I haven't been successful. Can anyone assist me in resolving this error? The specific error that I am encountering is from the initial code snippet which reads: "Notice: Un ...

I am looking for a way to showcase the form value either in the address bar or transfer it to another page using JavaScript. Can

Currently facing a challenge with a form where I need to input the name and email, redirect these values to another page, and display them in the address bar using only JavaScript. Take a look at the form here: View Form Code snippet for the form: <f ...

Safari Displaying Error Message "Unhandled Promise Rejection: [object DOMError]" While Playing MP4 Video

I am facing an issue with playing a group of MP4 videos on hover in a container. You can view a demonstration by clicking the link below: While this functionality works smoothly in Chrome, it seems to be causing problems in Safari. Upon hovering, the vide ...

At what specific times is it most appropriate to use parentheses when dealing with functions?

Check out my code snippet below: const cleanRoom = function() { return new Promise(function(resolve, reject) { resolve('Cleaned The Room'); }); }; const removeGarbage = function(message) { return new Promise(function(resolve, reject) ...

Updating the parent page host within a cross-domain iframe: issues encountered in Firefox and Chrome browsers

I am encountering an issue with my iframe app where I am receiving an alert indicating "-error" in Chrome related to top.location.href. jQuery.ajax({ type : 'get', url : 'check_if_fb_data_set.php', success ...

Web API 2 failing to deserialize JSON data

I have been facing an issue while calling a web service API in my application. I am passing a parameter, but the JSON is not deserializing as expected. Instead, it is treating the JSON as a string. Below is the code for the API: [Route("api/v1/images/GetM ...

The outcome of the JSON response is that the property 'fillColor' cannot be defined in ChartJS

UPDATE Currently, I am only able to view the image linked below: https://i.stack.imgur.com/hkkeY.jpg UPDATE END This piece of PHP code fetches multiple rows from a MySQL database and encodes the result using json_encode. This allows us to retrieve it i ...

Do double forward-slash comments work in CSS code?

Is using a double-forward slash (//) for single-line comments in CSS considered reliable and supported by mainstream browsers and CSS interpreters according to the specification? ...

Tips for streamlining the filter function using replace and split:

Currently, I am utilizing a filter function alongside replace() and split(). Here is the code snippet: jQuery('table .abc').filter((i, el) => jQuery(el).text(jQuery(el).text().replace('a', 'b').split(' ')[0] + &ap ...

jQuery.clone() Internet Explorer issue

I have a scenario where I use jQuery.clone() to extract the html of a page and then append it to a pre tag. Surprisingly, this operation works perfectly fine in Firefox and Chrome, but there's no response when it comes to IE: <!DOCTYPE html> &l ...

Showing a PDF from a shared folder on a network using AJAX in HTML5

I'm facing a challenge with displaying a PDF on the web. The layout includes a dropdown menu on the left with various PDF file names, and upon selection, the chosen PDF should be displayed on the right using an ajax call. Since my PDFs are stored in a ...

Customizing Material UI CSS in Angular: A Guide

Recently, while working with the Mat-grid-tile tag, I noticed that it utilizes a css class called .mat-grid-tile-content, which you can see below. The issue I am encountering is that the content within the mat-grid-tile tag appears centered, rather than f ...

Order of tabs, dialog, and forms customization using Jquery UI

I'm currently working on a jquery dialog that contains a form split into multiple tabs. In order to enhance keyboard navigation, I am looking for a way to make the tab key move from the last element of one tab to the first element of the next tab. Cur ...

Ways to make a DIV element extend to fill the height of its parent container

Need help with stretching two child DIVs in a Bootstrap 5 page to match the height of the parent DIV. Can anyone assist? Here is the HTML: https://jsfiddle.net/og7pz9sq I'm attempting to make the light-green and light-yellow DIVs fill the entire whi ...

Updating information with AJAX upon clicking a hyperlink

I am trying to implement AJAX for replacing the contents within a div. The setup of the application is quite complex, but I have simplified it to focus on getting the basic concept to work first. Currently, my goal is simply to replace a div based on the ...

Slideshow not displaying properly after an Ajax request due to CSS not being applied

My goal is to dynamically load data when reaching the bottom of a page using the onScroll event handler. The data to be loaded mainly consists of slideshows and, behind each one, within a separate div, there is an iframe with embedded vimeo content. Initi ...