What is the best way to ensure the image and card maintain the same size ratio in React Bootstrap?

One of the challenges I encountered involved a vertically aligned card group containing a card with an image:

https://i.stack.imgur.com/w9Jkf.jpg

This is the React code snippet that was causing the issue:

import React from 'react';

import { Container, CardGroup, Card, Row, Col } from 'react-bootstrap';

const styles = {
  card: {
    backgroundColor: '#B7E0F2',
    borderRadius: 55,
    padding: '3rem'
  },
  cardImage: {
    objectFit: 'cover',
    borderRadius: 55
  }
}

export default function FindingsPage() {
  return(
    <Container fluid>
      <CardGroup className="m-5 d-block">
        <Card className="m-5 border-0 shadow" style={styles.card}>
          <Row>
            <Col>
              <Card.Img src={require("../assets/images/findingsPage/EnglishesOfTheWorld.jpg")} style={styles.cardImage} />
            </Col>
            <Col>
              <Card.Body>
              <Card.Title as="h1">Englishes of the World</Card.Title>
              <Card.Text as="h4" style={styles.cardText}>
                How do your grammar intuitions depend on when and where you learned English? Participants took a short grammar quiz, which we are using to understand how grammar differs in different parts of the English-speaking world (USA, Ireland, Australia, etc.). We are also investigating how grammar is different for people who learn English later in life: Do they make different mistakes if their first language is German as opposed to Japanese?
              </Card.Text>
              </Card.Body>
            </Col>
          </Row>
        </Card>
      </CardGroup>
    </Container>
  )
}

Unfortunately, when the length of the text exceeds the height of the image, the image does not stretch to accommodate it:

https://i.stack.imgur.com/9bMO7.jpg

I am seeking advice on how to address this issue. Thank you.

Answer №1

Nice job! To optimize your images for better performance, consider using the following width and height values:

120px
40vw
25em
calc(60vw-15px)

In simpler terms:

imageContainer: {
objectFit: 'cover',
borderRadius: 65,
width: '60vw',
height: '35vh'
}

For additional information, check out this resource: https://web.dev/serve-responsive-images/

Answer №2

I finally solved it by simply including height: '100%' in the cardImage section of the styles.

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

Issue with executing a server-side function in a Next.js application

I'm encountering an issue with my Next app. I have a method in my ArticleService class that retrieves all articles from my SQL database. async getArticles(): Promise<IArticle[] | ServiceError> { try { const reqArticles = await sql< ...

Troubleshooting problem with CSS scaling on smartphones

I'm attempting to create a website (the first one I've ever designed) dedicated to my girlfriend's cat. However, when viewed on a mobile device, it doesn't look good. I've made an effort to adjust the meta viewport tag, but it does ...

Components will be displayed without any gaps on smaller screens

I attempted to apply styles to two components in order to create space between them, visible on both larger and smaller displays. The code snippet appears as follows: <div> <CustomPageHeader pageTitle={t('offersPage.pageHeader')} ...

Incorporating a URL into an HTML marquee

As a beginner in coding, I'm currently exploring how to incorporate a link into my marquee. My goal is to eliminate any color change or underline animation as well. Do you have any recommendations? .Marquee { color: #da6fe2; background-color: t ...

Cursor hovers over button, positioned perfectly in the center

I am facing a challenge with implementing a hover function for a set of buttons on the screen. The goal is to display the mouse pointer at the center of the button upon hovering, rather than the actual position of the cursor being displayed. I have tried u ...

I am receiving all NFT IDs when I should only be getting the ones that are associated with the current account

I am facing an issue where I am receiving all NFTs token IDs instead of just the one that belongs to the current account. The code snippet causing this problem is as follows: const { enableWeb3, account, isWeb3Enabled, Moralis, deactivateWeb3 } = useMorali ...

An adequate loader might be required to manage this specific file format, which involves loading an image within a React application

I'm having trouble loading an image from my static/images folder, and I keep getting this error message: Avatar.jpg:1 Uncaught Error: Module parse failed: Unexpected character '' (1:0) You may need to configure a loader to handle this file ...

Changing the background color of the canvas using Javascript

I want to create a rect on a canvas with a slightly transparent background, but I don't want the drawn rect to have any background. Here is an example of what I'm looking for: https://i.stack.imgur.com/axtcE.png The code I am using is as follo ...

How CSS can affect the layout of elements on a webpage

I am looking to achieve something similar to this: The left box should maintain a fixed width, while the right one resizes to fit the full width of the browser window. I also need the height of both boxes to be resizable. Apologies for any inconvenience ...

Encountering a CORS error in my Next.js 13.4 application while attempting to retrieve JSON data

Here is the location of the actual fetch request in our search/page. import { useSearchParams } from "next/navigation"; import Footer from "../components/Footers"; import Header from "../components/header"; import { format } ...

Running a NodeJS Redux example of a Todo List

While browsing through the Redux documentation, I stumbled upon an example app located here. I have a question about how to run this example app on a Node.js server and preview the results in a browser. Would it be better to use Express.js as the framewo ...

Customizing table row background color on hover or mouseover in Material UI datatable

Completely new to React and Material-UI. I'm attempting to modify the color of table rows when hovering over them with the mouse. I have tried various solutions from different posts but none have worked for me. (e.g. Root, cell, and tableRow) The x ...

Discovering modifications to CSS using selenium

Currently, I am working on an ajax form where CSS elements are dynamically changed. I am curious to know if it is feasible to verify these changes using Selenium. For example, checking if the background color changes from #ffffff to #000000 after clicking ...

Underline Rows in CSS

When designing my website, I decided to organize the content into rows using CSS instead of tables. To create a line separating each row, I used height:px; for each row manually. However, this method resulted in the line jumping around inconsistently acr ...

Tips for adjusting column spacing in HighCharts

Looking for some advice on how to make a chart container scrollable and properly space the labels and bars within a parent container with fixed width and height. The goal is to ensure all labels are visible and bars are well spaced. Any suggestions or tips ...

Customize the Width of DropDown List Items with Razor

I'm having trouble adjusting the width of items in a DropDownList. I want the width of the DropDown items to be different from the DropDown itself. Can anyone assist me with this? <div class="col-md-3"> @f.FormGroup().DropDownList("IdTipoAc ...

Utilize the div element to segment a webpage into four different sections

Within a div tag, I have used 4 other div tags to create equal areas. Is there an alternative method to achieve this division or improve it? <div style="width: 689px; margin-left: 215px; margin-top: 0px; float: none; height: 502px;"> ...

Strategies for incorporating a design in Next.js

Currently, I'm developing a frontend project using Next.js and Tailwind CSS. I have received a Figma design to incorporate into the project. One of the sections requires me to display a series of steps: https://i.stack.imgur.com/gDmGQ.png Do you hav ...

I am experiencing difficulties with my HTML and CSS code not functioning as I had initially intended

I've been dabbling in HTML and attempting to create my own website, but I'm encountering an issue with the positioning of my <table> tag. It keeps appearing at the bottom of the site, despite my CSS instructions to prevent it. The position ...

Nextjs does not allow for loading different pages within a Shopify embedded app

When I load a new page using the nextjs router, it doesn't work properly as the new page appears blank. There seems to be no client-side or iframe-based navigation redirection happening. Although I have been able to navigate from page to page using P ...