Tips for arranging all content within React-Bootstrap cards using flexbox

In my project using React Bootstrap, I have movie cards that include images, text, and buttons. However, the content inside the cards keeps overflowing, and I need all cards to have equal height. The project was initially built with Bootstrap during a bootcamp, and now I'm looking to refine it. I've been attempting to use flexbox for the cards, but I'm encountering some difficulties. EDIT: I want the cards to maintain their current appearance with overflowing text hidden from view without showing partial content.

https://i.sstatic.net/Ixp2K.png

Desired Outcome (Note how the text is cut off without displaying partially)

https://i.sstatic.net/Hj2BT.png

<Card className="cardClass">
    <div style={{textAlign: 'center'}}>
       <Card.Img  className="card-image" variant="top" src={movie.ImagePath} />
    </div>
   
    <Card.Body>
      <div className="card-text-body">
        <Card.Title>{movie.Title}</Card.Title>
        <Card.Text>{movie.Genre.Name}</Card.Text>
        <Card.Text className='card-description'>{movie.Description}</Card.Text>
         <Link to={`/movies/${movie._id}`}>
          <Button className="movieCard-btn" variant="primary">View Movie</Button>
        </Link>
      </div>
    </Card.Body>
  </Card>

.card {
    margin-bottom: 4rem;
    background-color: rgb(247, 247, 247);
}

.cardClass {
    max-width: 100%;
    height: 400px;
}

.card-image{
    width:  100px;
    height: 150px;
    object-fit: cover;
    text-align: center;
}

.card-title {
    font-weight: 900;
}

.card-text-body {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.card-description {
    font-size: 13px;
    overflow: hidden;
}

.card-body {
    font-weight: 400;
}

.movieCard-btn {
    width: 100%;
    margin-top: 1rem;
}

.btn .btn-primary {
    text-align: center!important;
}

.btn-primary {
    color: black;
    background-color: goldenrod;
    border-color: black;
}

.btn-primary:hover {
    color: black;
    background-color: goldenrod;
    border-color: black;
}

a {
    text-decoration: none!important;
}

Answer №1

Here are two different approaches you can take:

Method One:

To limit the number of characters in the description, you can do something like this:

let description = movie.description;    
if (description.length > 120) {
    description = description.substring(0, 120);
}

Method Two:

  • Ensure the card fills 100% height to utilize remaining space.

  • Set your title to flex-grow: 1 to push other elements below it.

  • Make sure to specify a height for the description box and use overflow: hidden;

    .card {
        margin-bottom: 4rem;
        background-color: rgb(247, 247, 247);
        height: 100%;
    }
    
    .card-title {
        font-weight: 900;
        flex-grow: 1;
    }
    .card-description {
        font-size: 13px;
    
        overflow: hidden;
        height: 100px;
    }
    

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

Move the menu button to the right of the title slide, beyond the edge of the card

Having an issue with the MuiCardHeader component. <CardHeader disableTypography avatar={renderAvatar()} action={ <IconButton onClick={toggleMenu}> <img src={MoreIcon} alt=""/> </IconButton ...

Combining blend-mode and filter in CSS: A comprehensive guide

Looking to achieve a specific image style by transforming a full color photo in the following ways: Convert it to greyscale Adjust the black levels (via decreased opacity or brightness) Apply a "multiply" blend mode with a blue color overlay So far, I&a ...

Is it possible to utilize dynamic imports in conjunction with a for loop in Next.js?

I often use dynamic import to bring in multiple components efficiently. Is it feasible to use a 'for' loop for this purpose? import dynamic from "next/dynamic"; let Dynamic = []; for (let i = 1; i < 80; i++) { const DynamicComponent = d ...

Creating a stylish border for a div element

Having trouble with styling a border around a div box. I'm struggling to find a way to prevent the borders from looking like this: Let me show you an example of what I'm dealing with: .num.num_1 { border-left-color: #0D2431; } .num { wid ...

Changing colors using JavaScript: A step-by-step guide

Hey there! I'm looking to change the color code in this script from $("#Tcounter").css("color","black") which uses the color word "black", to "#317D29". Can someone help me figure out how to do this? <script type="text/javascript"> $(document). ...

Issue with z-index causing the image to not display when navigating through an image gallery with previous and next buttons using

$(document).ready(function(){ $(".divs div.panel").each(function(e) { if (e > 2) $(this).hide(); console.log(e); }); $("#next").click(function(){ if ($ ...

You must use the 'new' keyword to invoke the class constructor NextResponse | Implementing middleware in Next.js | Implementing role-based protection for routes in Next.js |

I've been working on implementing user role-based protected routes in my next.js project using middleware.js, but all of a sudden, I've encountered this issue. I'm not exactly sure why this is happening, so if anyone has a better approach to ...

Reducing the gridview size with the help of the Bootstrap framework's stylesheet

Seeking advice on adjusting the size and alignment of a Gridview in asp.net web forms using bootstrap stylesheets. Here's the code snippet in question: <table class="table table-sm" > <a ...

Utilize a value passed from one React component to another React component

I am working on developing a React tabbing component and I want to export two React components from one file: one for the header tab labels and one for the tabs panel. Here is my code: import React, { Component } from 'react'; export class Tab ...

When reducing the page size, the Bootstrap columns are colliding with

While resizing the screen, I noticed that these images are overlapping each other. I haven't made any changes to the css for container-fluid or row. <div class="container-fluid bg-grey"> <div class="row center"> <div class= ...

Creating a dynamic menu layout using CSS

I've experimented with various methods to create a fluid menu, but none have been successful. Currently, I have an interactive menu that sometimes displays 6 items and other times 7 items. When I have 7 items, the menu aligns perfectly across the wid ...

Tips for centering text and icon on a Bootstrap navigation bar

I am currently developing an Angular 4 application that includes a navigation bar with text and font awesome icons. While the UI looks good in web view, I'm facing alignment issues when it comes to mobile view (minimized screen). Despite my efforts, ...

What is the best way to incorporate animation and highlight a newly inserted row in a table without altering the styles of existing rows?

In my Nuxt 3 or Vue 3-based application, I am utilizing the HTML Table and incorporating a row into it through a button click. As I add a new row, I desire to implement a form of transition/animation so that the freshly added row is displayed with an anim ...

Displaying Props Information in a Modal Window using React

Currently venturing into the realm of React JS, where I am in the process of developing a sample eCommerce application for real-time use. However, I have hit a roadblock. In my Products List, there is a Buy button for each product. When clicking on this b ...

Tips for automatically resizing a canvas to fit the content within a scrollable container?

I have integrated PDF JS into my Vue3 project to overlay a <canvas id="draw_canvas"> on the rendered pdf document. This allows me to draw rectangles programmatically over the pdf, serving as markers for specific areas. The rendering proces ...

Steps to access a Windows folder after clicking on a link within an HTML page using Asp.net

I attempted to use the following code : <a href="file:///C:\Programs\sort.mw">Link 1</a> <a href="file:///C:\Videos\lecture.mp4">Link 2</a> Unfortunately, this code does not work in Google Chrome or Firefox bro ...

What is the best way to ensure that the draggable element remains visible on top of all other elements on the screen while being dragged?

Currently, I am working on implementing the drag and drop feature in SAPUI5 Table and Tree Table. In my project, there is a table containing names that need to be draggable, and a Tree Table where these names should be droppable. To achieve this function ...

Refresh the CSS inheritance and hover effects

Facing an issue with my web project where I am using CSS. At times, I need to reset the inheritance from the parent class for certain elements. Although I have defined some classes to style my elements, I want to completely reset all styles except for hove ...

Enhancing Password Strength Validation with Formik and Yup in a React Application

I am new to React and currently working on a signup page where I need to validate the password field using Regex. While utilizing Formik and Yup for validations, I encountered an issue where it shows the error that the property being called by the length ...

Guide: "Adding markers to user-uploaded images - A step-by-step tutorial"

I'm struggling to create a website that allows users to upload images and use specific tools. However, I am facing an issue where the marker I want to add is appearing all over the webpage instead of just on the image itself. How can I confine it to o ...