How can I switch between columns in a dual-column layout?

In my latest project, I utilized CSS Flexbox to create a sophisticated two-column layout that allows toggling each column independently. While this functionality is exactly what I need, I can't help but feel that my current method is somewhat cumbersome. To achieve the two-column layout, I have to manually set the height of the container, which feels like an impractical solution. One approach could be to dynamically calculate the height based on the number of columns, but I find this less than ideal as well. When I experimented with using rows instead of columns, both row elements collapsed or expanded simultaneously, which was not the desired outcome. Please see the provided code snippet and design below. So, my question stands: Is there a more elegant and efficient solution to achieve this layout?

HTML

<div class="flex-grid">
   @foreach($parents as $parent)
      <div class="col">
         <div class="header-group group-toggle" id="{{$parent->id}}">
            <h4><a href="{{ url($parent->url()) }}">{{ $parent->name }}</a></h4>
                 <div class="chev-icon">
                    <i class="fas fa-chevron-right rotate"></i>
                  </div>
          </div>
        <div class="sub-group collapse in">
              @include('group.child', $parent)
        </div>
     </div>
   @endforeach
 </div>

CSS

.flex-grid {
   display: flex;
   flex-flow: column wrap;
   align-items: center;
   justify-content: flex-start;
   align-content: center;
   height: 1200px;

   .col {
     width: 50%;
   }
}

Jquery

$('.group-toggle').on('click', function () {
    if ( !$(this).next().hasClass('in')) {
        $(this).parent().children('.collapse.in').collapse('hide');
    }

    $(this).next().collapse('group-toggle'); 
}

Design

https://i.stack.imgur.com/Q8hiM.png

Answer №1

If my understanding is correct, this issue should be resolved quickly. The concern regarding the height of the columns can be directly fixed by adjusting the flexbox configuration.

Instead of utilizing column for flex direction and wrap for flex wrap...

flex-flow: column wrap; /* shorthand for flex-direction:column and flex-wrap: wrap */

...I suggest changing the direction back to the default row and disabling wrapping. This will result in a layout where each .col item has uniform height:

flex-direction: row;
flex-wrap: no-wrap;
height: 100%;

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

Maintain the flow of a floated or absolutely positioned element using CSS

Is there a way in CSS to ensure that floated or absolutely positioned elements remain within the flow? I find it frustrating that CSS lacks something like flow:on and flow:off to control this. The main issue I am facing is with having a div element of var ...

Verify that the item has been successfully loaded

My website contains an iFrame along with various other content like images. I am using jQuery's $(document).ready(function() { ... }); to run code that manipulates the content within the iFrame. However, I need to ensure that the iFrame is fully loade ...

Having trouble directing input to embedded swf upon page load in Opera

I have created a basic HTML file designed to display embedded flash content immediately upon loading, without requiring any prior interaction. Unfortunately, I have encountered an issue in my preferred browser, Opera. The problem seems to be isolated to th ...

Numerous jQuery pop-up windows are being generated instead of just one as intended

When I load an editing form asynchronously on my web page using jQuery.get and display it within a jQuery dialog, multiple instances of the div that I apply .dialog to are unexpectedly being appended to document.body. Here is the code snippet for loading: ...

What is the reason behind $() not functioning properly while jQuery() works flawlessly?

I am experiencing an issue where $("#register") is returning null, while jQuery("#register") correctly returns an object. A picture is worth a thousand words: As shown in the Watch expression, everything is functioning as expected (jQuery === $ returns t ...

Guide to setting up FullCalendar views based on unique identifiers

Currently, I am working on an MVC project that focuses on tracking vacation days taken by employees. My goal is to display these dates using FullCalendar for each individual employee. At the moment, I can only showcase all employees or none at all, so I am ...

Transfer PDF file to user's web browser through XMLHttpRequest, utilizing up-to-date HTML5 techniques, all while maintaining the integrity of the document's encoding

I am trying to achieve a similar result as described in this StackOverflow post about handling file download from ajax post. However, I'm working with a dynamically-generated PDF file created using PHP v5.6.10 (with the PDFLib extension, v9.0.5). Unf ...

fancybox appears to be experiencing issues with loading ajax content

Here is the code I am working with: $(document).ready(function(){ $("a#cakeImages").live("click",function() fancybox({ 'titleShow' : false, 'transitionIn' : 'elastic', 'transitionOut' : ...

Modifying HTML code within a WebView (Monodroid) explained

WebView webView = FindViewById<WebView>(Resource.Id.webView1); webView.HorizontalScrollBarEnabled = false; webView.LoadUrl("res.htm"); I am looking for a way to modify certain parts of HTML code in my file and display it using webView without actual ...

Refreshing Knockout Model

Recently, I started learning Knockout and I'm facing a challenge with updating my ViewModel after an ajax call. Below is the current setup: LoanDeductions.js var deductionLine = function (deductionID, deductionName, amount) { self = this; ...

Challenges encountered while using Selenium WebDriver to upload images

I'm having trouble adding an image as a normal attachment to an email (not as an inline image). When inspecting the HTML DOM with Firebug, I noticed there are two elements with xpath //input@type='file', which is due to the presence of two b ...

Updating a database field in Rails based on a selection from a dropdown menu: A step-by-step guide

Seeking guidance in Ruby on Rails - I have a dropdown menu bar and would like to update the database table based on the selected item from the dropdown menu. _applied_candidate.html.erb is the partial page I am working with. <p>Current Status: < ...

Troubleshooting Angular MIME problems with Microsoft Edge

I'm encountering a problem with Angular where after running ng serve and deploying on localhost, the page loads without any issues. However, when I use ng build and deploy remotely, I encounter a MIME error. Failed to load module script: Expected a ...

Scrolling vertically using window.open functionality

I am trying to open a pop-up window using window.open. I would like the scrollbars to appear only if necessary. Unfortunately, in Safari, the scrollbars do not show up unless I include scrollbars=1 in the code. However, this also causes horizontal scrollb ...

Diagonal-left ending div in cascading style sheets

Looking to achieve a div with a diagonal side similar to the image in the link below: I'm trying to figure out the best way to do this. One idea is to position 2 divs closely together and rotate one of them. Alternatively, I could use a background im ...

What is the best way to create a CSS class for a list element in React?

I am facing an issue with styling buttons in my UI. These buttons represent different domains and are dynamically generated based on data fetched from the server using the componentDidMount() method. Since I do not know the quantity of buttons at the time ...

The issue with Jquery Tooltip not functioning after a postback

Hello everyone, I'm facing an issue with my tooltip. When I initially load the page, I am able to hover over the image linked to the tooltip. The image is the only one in the table named "mytable," so jQuery identifies it from there. However, the prob ...

Adjust the width of a container as its children expand

My current project involves creating a dynamic gallery using JavaScript and jQuery, where full-sized images slide out from the right side. I have successfully implemented this functionality, but now I am facing a new challenge. I need the parent block of t ...

Where can I locate htmlWebpackPlugin.options.title in a Vue CLI 3 project or how can I configure it?

After creating my webpage using vue cli 3, I decided to add a title. Upon examining the public/index.html file, I discovered the code snippet <title><%= htmlWebpackPlugin.options.title %></title>. Can you guide me on how to change and cu ...

The mobile navigation in HTML has a slight issue with the ::after pseudo-element, specifically within the

As I prepare to launch my website, I have made adjustments to the mobile layout by moving the navigation links to a navigation drawer. The template I am using included JavaScript scripts to handle this navigation change. However, I encountered an issue whe ...