Synchronized Height Bootstrap Cards Inside Slick Carousel

I am encountering difficulties achieving equal height bootstrap cards with varying length body content when using a slick carousel. Despite searching for solutions on similar issues, none of them seem to work in my specific situation.

While I have successfully achieved equal height slides, I am struggling to make the cards within the slides occupy 100% height of the slide (parent container). My goal is to replicate what the Bootstrap class 'card-deck' accomplishes but within a carousel.

HTML

<div class="container">
        <div class="row>
            <div class="col-10 mx-auto s_container">
                <div class="slider">
                    <div class="card">
                        <img class="card-img-top" src="img-ph.jpg" alt="place holder">
                        <div class="card-body">Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptates, rem?</div>
                        <div class="card-footer">
                            <a href="#" class="btn btn-primary">More Info</a>
                       </div>
                   </div>
                    <div class="card">
                        <img class="card-img-top" src="img-ph.jpg" alt="place holder">
                        <div class="card-body">Lorem ipsum dolor sit amet consectetur adipisicing elit. Rem, quasi soluta dolorum pariatur hic porro.</div>
                        <div class="card-footer">
                            <a href="#" class="btn btn-primary">>More Info</a>
                    <</div>
                  </div>
                 </div>
             <div>
         </div>
    </div>
 

CSS

.s_container{
margin: 0 auto;
padding: 0 40px 0 40px;
width: 100%;
}

.slider{
border: 2px solid red;
}

.slick-track {
display: flex !important;
}

.slick-slide {
margin: 12px;
height: auto;
border: 2px solid green;
}

.slick-frame {
visibility: hidden;
}

An example of this in action can be viewed here:

Example Link

Answer №1

For many developers, achieving equal height has been a persistent challenge. In my view, there are two viable solutions:

  1. Javascript solution

The approach involves iterating through all the cards to determine the tallest one. Once identified, set all cards to this maximum height using JavaScript.

https://www.bootply.com/LnwZjxWe7L

// Accessing card elements
var cards = $('.card-body');
var maxHeight = 0;

// Calculate the maximum height among cards
for (var i = 0; i < cards.length; i++) {
  if (maxHeight < $(cards[i]).outerHeight()) {
    maxHeight = $(cards[i]).outerHeight();
  }
}
// Set ALL card bodies to the calculated height
for (var i = 0; i < cards.length; i++) {
  $(cards[i]).height(maxHeight);
}
  1. CSS only solution

This alternative is more intricate and requires detailed explanation. Here's an example implementation:

#container3 {
    float:left;
    width:100%;
    background:green;
    overflow:hidden;
    position:relative;
}
#container2 {
    float:left;
    width:100%;
    background:yellow;
    position:relative;
    right:30%;
}
#container1 {
    float:left;
    width:100%;
    background:red;
    position:relative;
    right:40%;
}
#col1 {
    float:left;
    width:26%;
    position:relative;
    left:72%;
    overflow:hidden;
}
#col2 {
    float:left;
    width:36%;
    position:relative;
    left:76%;
    overflow:hidden;
}
#col3 {
    float:left;
    width:26%;
    position:relative;
    left:80%;
    overflow:hidden;
}
<div id="container3"> <!-- added -->
    <div id="container2"> <!-- added -->
        <div id="container1">
            <div id="col1">Column 1</div>
            <div id="col2">Column 2</div>
            <div id="col3">Super long text! Wow looks at this text, it is so long it needs to break on multiple lines!</div>
        </div>
    </div> <!-- added -->
</div> <!-- added -->

This CSS-based technique was sourced from:

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

Utilizing React and Material-UI to Enhance Badge Functionality

I am exploring ways to display a badge icon when a component has attached notes. I have experimented with three different methods and interestingly, the results are consistent across all of them. Which approach do you think is the most efficient for achiev ...

Shadow box with arrow/bubble element using CSS

I am looking to add a box shadow around the outline of the bubble below. <div class=speech-bubble-dark></div> .speech-bubble-dark { position: absolute; background: #fff; box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.2); border-radius: 0.4em; ...

Automate the process of opening an ngbpopover from an Angular 2 component using programming techniques

Currently, I am referring to this specific article in order to integrate Bootstrap with Angular 2. While the instructions in the article are helpful, there seems to be a lack of information on how to pass the popover reference to a component method. The on ...

Ways to showcase a website within an HTML document using a URL?

Is it possible to show 2 webpages on a single aspx webpage? For instance, When a user opens the link for www.mywebsite.com, I would like to display both www.google.com and www.bing.com on my homepage. Behind the scenes, I will call two separate URLs an ...

nsIStyleSheetService - The Gateway to Stylish CSS

I am currently utilizing nsIStyleSheetService within my Firefox extension to apply a custom stylesheet to every webpage. While everything is functioning properly, there are a few styles that are not being applied as expected. One of the styles causing iss ...

Having trouble utilizing vue-bootstrap's $bvModal feature in Vuejs for dynamic modal rendering

Is there a way to dynamically render modal of vue-bootstrap without writing any HTML code? I encountered an error when trying to utilize bvModal.msgBoxOk('sad') in my Vue project after referring to the documentation at BootstrapVue Modal Message ...

Unable to adjust font weight as intended

I'm encountering an issue with getting the lighter font weights to display correctly. Despite having all the necessary font weights installed on my computer, it seems that many fonts do not support the lighter options. What could be causing this incon ...

What are the ways to ensure my query columns fill the entire page space?

Currently, when I execute a query, it retrieves the correct information. However, I want to make my columns span across the entire page instead of being centered in the middle with empty space on the sides. Is there a way to expand the columns? Below is t ...

I'm facing an issue where I am unable to connect images to specific pages within my carousel using Bootstrap on

Trying to link images in a carousel to pages on my website but encountering issues. Followed advice from other answers (Href in Bootstrap Carousel). Added the necessary href and included the correct .js from the Bootstrap site. The link is on the same host ...

Craft a circular design with an Arc and a Pie using the DIV DOM element

After creating an ellipse using the div DOM element, here's how I did it: var body = document.querySelector('body'); var div = document.createElement('div'); div.style.borderRadius = '50%'; div.style.border = '1px s ...

The presence of an image within an HTML anchor is causing an unexpected artifact to

Currently, I am working on a simple header design, but there seems to be a strange issue with the anchors containing image tags. The problem can be seen in the screenshot below: Image Link Here is the HTML structure: <div class="block-content"> ...

Having Trouble with jQuery toggleClass

I'm currently working on a project where I have implemented a button that displays a menu when clicked. I am attempting to change the color of the button when it is active, however, the toggleClass function is not behaving as expected. Below is the co ...

ways to halt a noise once an animation is complete

I don't have much experience with coding in general, but somehow I've made it this far. Now I'm stuck on the final piece of the puzzle. This is related to a Twitch alert that I'm setting up through 'Stream Elements'. The iss ...

How can I trigger a CSS animation to replay each time a button is clicked, without relying on a timeout function?

I am having trouble getting a button to trigger an animation. Currently, the animation only plays once when the page is refreshed and doesn't repeat on subsequent clicks of the button. function initiateAnimation(el){ document.getElementById("anima ...

Align the last line of flex cells to the left side

I have created a flex structure that resembles a table and adjusts the number of cells based on the content. However, when the last row is not full, the remaining cells stretch to fill the empty space, which affects the overall appearance of the structure. ...

Ways to ensure that two divs have equal heights based on whichever one has the greater height using CSS

I need help with adjusting the heights of two divs inside a container div using CSS. Specifically, I want the height of the img_box div to match the height of the content_con div based on their actual content. For example, if the content_con div contains t ...

Ways to reduce lag while executing a for loop

How can I optimize my prime number generation process to avoid lagging? For example, is there a way to instantly display the results when generating primes up to 1000? HTML: <!DOCTYPE html> <html> <meta name="viewport" content="width=dev ...

Customize Bootstrap to change the hover color of a button

I'm currently working on customizing the style of my buttons so that when hovered over, they become a lighter shade instead of a darker one. I've explored the Bootstrap customization page (http://getbootstrap.com/customize/), but unfortunately, t ...

Exploring ways to animate a conditionally displayed component when the state changes using a combination of javascript and css

I am encountering a scenario where I have a react component with a specific part that is rendered conditionally. Upon clicking on a visible element within the component (button), the state changes triggering the display of the hidden parts. However, inst ...

Does the margin fall within the element's boundaries?

Consider this code: <html> <head> <title>Understanding CSS Box Model</title> </head> <body> <section> <h1>An example of h1 inside a section</h1> </section> </body> </html& ...