I'm new to the front-end world, and I'm trying to make a "responsive" card grid, meaning I want to place an unknown number of cards inside a grid and make the text and layout fit nicely. I'm using react-bootrap Card and CardGroup, this is what I got so far.
If I use too many Cards, they get horizontally stretched and don't create new rows for a better layout, I'd expect to have a min-width so if it doesn't fit it creates a new row, but I'm not sure how to get this done or if it's the best practice.
Sorry if some of the terms are incorrect; I just started learning as mentioned.
Here is my GridCard.js code
import React from "react";
import {Card, CardGroup, Button} from "react-bootstrap";
import "./CardGrid.css"
const CardGrid = () => {
return (
<CardGroup>
{Array.from({ length: 10 }).map((_, index) => (
<Card className={"card-grid"} key={index}>
<Card.Img className={"card-img"} variant="bottom" src={"https://cdn.pixabay.com/photo/2014/11/30/14/11/cat-551554_960_720.jpg"}/>
<Card.Body>
<Card.Title><strong>Lorem ipsum dolor sit amet</strong></Card.Title>
<Card.Text>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolores harum, illum.
Accusamus assumenda commodi consequuntur cumque, delectus deleniti dolorum eum illum
nam nostrum provident quaerat quisquam quos reiciendis, reprehenderit voluptas!</p>
</Card.Text>
<Button variant="primary"
href="www.google.com"
rel={"noopener noreferrer"}>
Learn More
</Button>
</Card.Body>
</Card>
))}
</CardGroup>
)
}
export default CardGrid
and my CardGrid.css
.card-group {
justify-content: center;
}
.card-grid, .card {
padding: 5px 5px !important;
height: auto !important;
justify-content: center;
margin: 1rem;
}
.card-body {
background-color: #F6F5F5;
margin: 0;
}
.card-img,
.card-img-top,
.card-img-bottom {
height: 10rem;
width: auto;
align-content: flex-start;
}
.card-text {
height: fit-content;
margin-bottom: 2rem;
}
.btn, .btn-primary {
position: absolute;
bottom: 5px;
color: #263238;
overflow: auto;
}
