Increasing height for individual Bootstrap cards, without affecting all cards within the same row

I've encountered an issue where I need to increase the height of a single bootstrap card in a tile-module layout without affecting the height of any other cards in the same row. The code snippet below shows the HTML structure I currently have:

<div class="module tile-module">
    <div class="container">
        <div class="row">
            <div class="col-12 col-sm-12 col-md-4">
                <div class="card">
                    <div class="card-img-top">
                    </div>
                    <div class="card-body">
                        <h3>Title Here</h3>
                        <p class="card-text">Long text here...</p>
                    </div>
                </div>
                <div class="card">
                    <div class="card-img-top">
                    </div>
                    <div class="card-body">
                        <h3>Title Here</h3>
                        <p class="card-text">Long text here...</p>
                    </div>
                </div>
                <div class="card">
                    <div class="card-img-top">
                    </div>
                    <div class="card-body">
                        <h3>Title Here</h3>
                        <p class="card-text">Long text here...</p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

My aim is to dynamically show/hide the paragraph text in a card based on its length exceeding a certain number of characters. While I can implement JavaScript logic to toggle the visibility of the text, the problem arises when extending the height of one card affects all the cards in that section, rather than just the targeted card. I've tried applying CSS styles directly to the element instead of all elements with the same class, but it hasn't solved the issue.

Most online solutions focus on increasing the height for all cards in a row, which is contrary to what I'm trying to achieve. I'm struggling to find a solution without completely redesigning the layout to fit my needs. As a newcomer to Bootstrap, I'm unsure of the best approach to tackle this requirement.

Answer №1

It seems like the .card in Bootstrap utilizes flexbox for creating the tile layout, where a row of flex elements aims to maintain the height of the tallest element by default.

If you're looking for a way to handle this without relying on Bootstrap's built-in features, I can suggest an alternative approach using regular CSS.

You could experiment with adding align-self: flex-start; to the specific .card that is being expanded (perhaps by toggling a JavaScript class). This method is elaborated further in this discussion on Stack Overflow.

However, keep in mind that this modification may lead to complications in other rows and result in overlapping cards in unexpected ways.

To address this issue, you might consider creating a wrapper element to manage the flex properties and then, upon expansion, apply absolute positioning, z-index adjustments, and enable the content to expand beyond its original height.

HTML:

<div class="cardContainer>
   <div class="card">content of the card...</div>
</div>

CSS:

.cardContainer {
   position: relative;
}
.card.expanded {
   position: absolute;
   top: 0;
   left: 0;
   right: 0;
   /* no bottom position to allow content to expand beyond container */
   z-index: 50; /*use higher numbers for priority */
}

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 footer seems to detach on certain pages

Currently, I am facing a frustrating issue while working on a website. The footer seems to be disconnected from the main body content on certain pages, while on others, it appears to be properly attached. Despite my efforts to troubleshoot by removing elem ...

What is the fastest way to add an email subscription form to my website without needing to configure a database?

Would it be possible to integrate a sign-up text box on our site for users interested in receiving launch notifications? Any suggestions on the most effective method to implement this feature? EDIT: Our current use of Prefinery has limitations as we cann ...

Switch up the appearance of a button by altering its image depending on the value it holds

There are two buttons generated dynamically (not within my control) that I would like to customize with different images. Since I can't actually change the button code, I believe I will need to utilize CSS to achieve this based on the CSS values. The ...

Table with expanded width, cut off cell content

As I work on building an HTML table, I've encountered a challenge. The table code looks like this: This is the structure of my table: <table class="table" style="font-size:22px; width:100%"> I want to ensure that everything fits within the pa ...

Issues with hover functionality in React Material Design Icons have been identified

I'm facing an issue with the mdi-react icons where the hovering behavior is inconsistent. It seems to work sometimes and other times it doesn't. import MagnifyPlusOutline from "mdi-react/MagnifyPlusOutlineIcon"; import MagnifyMinusOutli ...

tips on adjusting images to the size of the screen without them being on html files

I understand that sharing links may not be appropriate for this forum, but I'm unsure how else to seek assistance. My apologies for any inconvenience. I am currently working on a website for a doctor, and the image you see is of a patient. I'm ...

The functionality of CSS columns is not supported in Firefox browser

Currently, I am working on a web page design inspired by Pinterest. However, I have encountered an issue where the columns property is not functioning properly in Firefox. You can find the example I am trying to replicate here. Feel free to test it in Fir ...

What is the best way to swap out text for an image in CSS?

I came across a website that I am working on: The site features a slider with 2 tabs named "TAB1" and "tab2" My goal is to replace the text with unique images for each tab Below is the CSS code snippet: .dnd-tabs.dnd-tabs-style1 .ui-tabs-nav li.ui-tabs ...

What is the best way to create a JavaScript animation for altering the width of a div element?

Need help with creating a dynamic poll chart based on YES and NO votes? Check out this project where you can visually see the results by clicking HERE. Looking to add some animation effects to your poll? You can achieve a smooth transition using CSS with ...

Issue encountered with CSS3 animations, failing to perform as intended for various animations

In my project, I have a series of div elements that I am animating in various ways. The first one utilizes a cardflip animation effect: @-webkit-keyframes cardflip { from { -webkit-transform: perspective(2000) rotateY(90deg); -webkit-tra ...

Avoiding overlapping of div elements in a stacked div layout

I have a challenge with creating a vertical layout of stacked divs. Everything was going smoothly until I encountered the #resume div, which stubbornly stays hidden beneath the table-containing div above it. Despite trying various adjustments to float and ...

jQuery's show/hide functionality allows for the dynamic resizing of images,

I am experiencing an issue with a Joomla template that has a custom jQuery menu. When I hover over the map with my mouse, the overlay appears slightly larger than expected. This problem seems to be occurring in Firefox and IE 11, leading me to believe it ...

What methods can I use to reduce the input field height while using floating labels?

Is there a way to reduce the input height when using a floating label? I attempted to adjust the size property but it had no effect. <Col xs={5} md={2}> <FloatingLabel size="sm" controlId="floatingInput" l ...

Tips for modifying style.display using JavaScript

On my website, the menu is structured like this: <nav id="menu"> <label for="tm" id="toggle-menu">Menu <span class="drop-icon">▾</span></label> <input type="checkbo ...

Position an image on the top left corner of a div's border

I have a situation where I'm trying to overlay a small square transparent image on the top left border of a div that has a 1px border. The image is 48px by 48px in size and I want it to give the illusion that it's going underneath the top and lef ...

CSS - fixed table headers

Check out my CodePen example here - Code In this demo, I have a table inside a container where the table is larger than the container. As you scroll horizontally, both the table and headers move accordingly. However, when scrolling vertically, I want th ...

The CSS zigzag border functionality seems to be malfunctioning on Internet Explorer

On my clients website, I decided to use a zigzag css border instead of an image for speed purposes. I wanted to have different colors and variations, but I encountered a problem. While my version displayed correctly on Chrome and Firefox using Windows, it ...

In Internet Explorer, transitions do not always play correctly when using ng-animate and ng-if

I am facing an issue with a simple div that has a transition effect. It goes from a yellow background to a red one. <div class="bar" ng-class="{'bar-visible': vm.visible}"> The transition works smoothly when the bar-visible class is added ...

The website appears to be loading in a unique way on mobile upon the second loading

While developing my personal website, I encountered a bug that occurs when accessing the site on my Android phone using Firefox or Chrome. The issue arises when the page initially loads correctly, but upon refreshing, the layout is displayed differently. ...

What is the best way to ensure that a Flex div and its child images stay confined within the boundaries of its parent container?

I'm struggling to create a responsive grid of images. I can't get the images to be both responsive with max-height and max-width, while also making sure the parent div takes up their full width. On the other hand, if I make the parent div the cor ...