Arrangement of content in three columns with a flex direction set to column

In my current project, I am working on creating a view of items that are mapped using React. The main objective is to set up a 3-column layout with items arranged vertically within each column. Each item panel contains a hidden div element which expands when the panel is clicked. This expansion should only affect content in that specific column.

I have experimented with different layouts such as grid and am currently exploring Bootstrap with traditional row and col flex properties utilizing percentages.

To simplify things, I have created two examples, both using jQuery to simulate the click functionality.

First example with grid: https://jsfiddle.net/lharby/vmaut95L/

Basic CSS:

.container {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  gap: 2em 2em;
  grid-auto-flow: column;
}

The problem with this approach is that clicking on an item with hidden content (panel 3) causes all panels to expand to the same size.

Here is the Bootstrap version: https://jsfiddle.net/lharby/u83L6tph/

While better, changing the flex direction to column results in all items appearing in a single left-aligned column with a width of 33% (col-md-4). This can be observed in the provided fiddle using standard Bootstrap CSS.

The markup structure remains similar but includes more Bootstrap utility classes:

<div class="row exclusive-offers-wrapper">
  <div class="col-md-4 mx-n1 p-4">
    <div class="item">
    </div>
</div>
...

The ultimate goal is to achieve a layout similar to the following: https://i.sstatic.net/Ay3HJ.png

Answer №1

While not a complete solution, I have found that Bootstrap 4 Cards meet several requirements. By utilizing simple markup, it is possible to achieve a masonry style layout. However, there is an issue where clicking on a card may cause some of them to shift position.

You can view the implementation in this jsfiddle link: https://jsfiddle.net/lharby/avfpq1sr/

The basic markup used is as follows:

<div class='card-columns'>
  <div>
    <div class='card item'>
      <h4>A heading</h4>
      <div class="hidden">
        <p class="mt-4 mb-5">Save up to 20% off* your business insurance thanks to....</p>
        <a href="https://www.goodlight.co.uk/wp-content/uploads/2017/07/goodlight-commercial-led-lighting.png" title="View" class="sc-pFZIQ iVCQdF cta btn-primary" target="_blank" rel="noopener noreferrer">View</a>
      </div>
    </div>
  </div>
  <div class='card item'>
    <div>
    ...
    </div>
  </div>
</div>

Despite trying alternatives like using height: 0 and overflow: hidden instead of display:none for the hidden content, the issue persists. Any insights or suggestions are welcome!

If you have encountered a similar situation before, feel free to share your experience. Your input would be greatly appreciated. Thank you!

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

Adjust the color of the input range slider using javascript

Is there a way to modify the color of my slider using <input type="range" id="input"> I attempted changing it with color, background-color, and bg-color but none seem to work... UPDATE: I am looking to alter it with javascript. Maybe something al ...

Positioning a div inside another div using CSS

I'm having issues with a nested div causing trouble for me. <div style="border:solid 20px #ccff33;border-radius:10px;height:300px;width:300px;margin:20px;display: inline-block"> <img src="images/f35.jpg" style="margin-right:10px" /> ...

Displaying a Bootstrap table with a sleek grey horizontal scroll bar during the printing process

When attempting to print a webpage with bootstrap tables, an unexpected horizontal scroll bar appears after pressing command/ctrl + P. It seems to be originating from some space below the table within the blue shed area. The resulting print preview shows ...

The functionality of Jquery and JS lies in working on DOM elements as opposed to

Just to start off, I want to mention that my knowledge of JavaScript and specifically jQuery is quite limited. I've encountered an issue with some JavaScript and jQuery loading on my webpage. 1) I have written some code on JSFiddle http://jsfiddle.n ...

Methods for animating .jpg images using CSS

I'm currently working on animating an image, specifically moving it from left to right and back. However, before I dive into implementing CSS animation keyframes, I noticed that I am having trouble getting the HTML element to follow the CSS styles I a ...

How to use Bootstrap 4 to align items to the bottom within a div using flex

Having a bit of trouble here. I'm attempting to align a gear svg image to the bottom center of a div, but no matter what I try, it just stays at the top of the div. I've experimented with both align-items-center and align-bottom options. Current ...

Infinite scrolling with a dynamic background

Hi there, I am working on my website and trying to create a smooth transition between sections similar to the one demonstrated here:. The challenge I'm facing is that the backgrounds of my sections cannot be fixed; they need to have background-attachm ...

After encountering a character with CSS, begin a new line

I have a CSV spreadsheet with data that looks like this: <p>Features:• first feature• second feature• third feature• fourth feature• and so on (the total number of features is variable)</p> I want each feature to display on a new li ...

Words with emphasized border and drop shadow effect

I am trying to achieve a specific font style. If it's not possible, I would like to get as close as possible to the desired style. However, due to IE support requirements, I am unable to use text-stroke. https://i.sstatic.net/JwQyb.png The closest a ...

Wrapping a list vertically with ASP.NET using a repeater for generation

I have a repeater that is creating a list of links in no particular order. I want the list to be displayed as follows: -Item1 -Item4 -Item2 -Item5 -Item3 Most solutions I've found require you to know the items in advance and set specific classes for ...

What could be causing my jQuery to malfunction after I include the .sqrt() function?

Seeking assistance in creating a grid of divs, I am working on finding the square root of the user's input to determine the height and width required to form a square. The code below is what I currently have: $('#size').click(function(){ $ ...

What is the best way to prevent content from spilling over into the div on the right

I'm having trouble with a two column div where the text in the left column is overflowing into the right column. How can I prevent this? http://example.com <div id="wrapper-industry"> <div id="wrapper-form"> <div id="form_row"> ...

Customizing Bootstrap css variables for a unique design

Currently, I'm working on tweaking the data-bs-theme in Bootstrap 5.3. My goal is to adjust the pre-defined CSS variables of the Bootstrap dark theme and refresh the color palette. Specifically, I want to change the shade of blue for my blue button (b ...

Using a background image from your own website does not display anything, but using an image from an

It's really strange from where I'm standing. I'm working on a website and trying to set up a banner with a background image using the background-image property. The issue I'm facing is: when I use two images with the same dimensions, ...

The CSS navigation bar is not properly aligned in the center

This menu was constructed by me: JSBIN EDIT ; JSBIN DEMO Upon closer inspection, it appears that the menu is not centered in the middle of the bar; rather, it is centered higher up. My goal is to have it positioned lower, right in the middle. I ...

How can we align divs in the center horizontally inside a parent div?

This question has been asked many times, but I can't seem to figure it out in my situation as I am new to HTML. I have three divs (boxes: QM, Audit, PM) and I want to center them within a parent div called Services. In the photo provided, you can see ...

What is the reason for having a space between the <body> and the <html> tags?

Can you explain why there is a gap between the top of the green box and the browser window in Chrome and Firefox? I've tried various CSS configurations to eliminate the apparent space between the html and body elements, but it seems that some padding ...

Using jquery to refresh several backgrounds at once

While I have some knowledge of CSS and various JavaScript libraries, I've encountered difficulty in integrating multiple backgrounds into the code that I found on this link: http://codepen.io/quasimondo/pen/lDdrF. My goal was to overlay a transparent ...

Once the database fetches and displays 500 results, the HTML/CSS formatting begins to

On my local webserver, I have a page running off SQLite as its database. Since it is used locally and loads results quickly, displaying all of them on one page isn't a concern. However, I'm facing an issue where the formatting goes awry after 500 ...

The equal height feature in Bootstrap 4's card-deck is not functioning as expected

I am having an issue with the card-deck property where it is not being applied correctly. The .card-deck class should create a grid of cards that are equal in height and width, and the layout should adjust automatically as more cards are added. Here is th ...