I am using React-bootstrap for my app, specifically the Card& CardGroup components. I want help please with making the cards all the same height.
JSX component:
<Card style={{flex: 1}} className="card">
<Card.Img variant="top" src={Weather} />
<Card.Body>
<Card.Title>Card title</Card.Title>
<Card.Text>
This is a wider card with supporting text below as a natural lead-in
to additional content. This content is a little bit longer.
</Card.Text>
<Button variant="primary">Go somewhere</Button>
</Card.Body>
</Card>
<Card style={{flex: 1}} className="card">
<Card.Img variant="top" src={Scheduler} />
<Card.Body>
<Card.Title>Card title</Card.Title>
<Card.Text>
This card has supporting text below as a natural lead-in to
additional content.{' '}
</Card.Text>
<Button variant="primary">Go somewhere</Button>
</Card.Body>
</Card>
<Card style={{flex: 1}} className="card">
<Card.Img variant="top" src={Quiz} />
<Card.Body>
<Card.Title>Card title</Card.Title>
<Card.Text>
This is a wider card with supporting text below as a natural lead-in
to additional content. This card has even longer content than the
first to show that equal height action.
</Card.Text>
<Button variant="primary">Go somewhere</Button>
</Card.Body>
</Card>
</CardGroup>
)
Related CSS:
.card {
padding: 30px;
margin-top:59px;
}
Here's what it currently looks like
enter image description here
I have tried using max-height and min-height, but it didnt work. I learned react a month ago and thus are trying to get acclimated with it. I would truly appreciate help on how to make these cards all the same height/size, regardless of the height of the photos. Or how to make the photo sizes the same as well.
Thank you so much
Not sure if I understand the desired result, but if the goal is to:
make these cards all the same height/size, regardless of the height of the photos
It seems that Card.Body is already taking the remaining space of Card, and it could be styled to align the text and button to the bottom, making the whole CardGroup aligned vertically.
The below example adds some bootstrap classes for this as a basic solution.
Live demo of the simplified example on: stackblitz
Example:
<CardGroup>
<Card className="card d-flex flex-column">
<Card.Img src={Weather} />
<Card.Body className="d-flex flex-column justify-content-end align-items-center">
<Card.Title>Card title</Card.Title>
<Card.Text>
This is a wider card with supporting text below as a natural lead-in to
additional content. This content is a little bit longer.
</Card.Text>
<Button variant="primary">Go somewhere</Button>
</Card.Body>
</Card>
<Card className="card d-flex flex-column">
<Card.Img src={Scheduler} />
<Card.Body className="d-flex flex-column justify-content-end align-items-center">
<Card.Title>Card title</Card.Title>
<Card.Text>
This card has supporting text below as a natural lead-in to additional
content.
</Card.Text>
<Button variant="primary">Go somewhere</Button>
</Card.Body>
</Card>
<Card className="card d-flex flex-column">
<Card.Img src={Quiz} />
<Card.Body className="d-flex flex-column justify-content-end align-items-center">
<Card.Title>Card title</Card.Title>
<Card.Text>
This is a wider card with supporting text below as a natural lead-in to
additional content. This card has even longer content than the first to
show that equal height action.
</Card.Text>
<Button variant="primary">Go somewhere</Button>
</Card.Body>
</Card>
</CardGroup>
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 days ago.
Improve this question
I have a container that is two sections left side and holds multiple divs that consist of a title and description and the right side of their pics but the container overflow is hidden and sticky.
I want to make it similar to the pics the right side container stays fixed or sticky with scrolling.
I know how to create the right side container and images appear at scrolling
but I cannot make it sticky and be in the center.
This is what I'm trying to achieve,
1st img
2nd img
<div className="flex flex-row w-full bg-red-900 ">
<div className="bg-red-300 w-full justify-center place-items-center">
<div className="h-screen justify-center flex flex-col space-y-3 bg-green-900 sticky top-0">
<span className="text-xl">Slemani Nwe Company</span>
<h1 className="font-semibold w-full text-5xl">
FMCG Distributer
</h1>
{/* map the tags and indexes seperate them with , */}
<div className="text-xl">Design, Development, Branding</div>
</div>
<div className="h-screen justify-center flex flex-col space-y-3 bg-green-900 sticky top-0">
<span className="text-xl">Slemani Nwe Company</span>
<h1 className="font-semibold w-full text-5xl">
FMCG Distributer
</h1>
{/* map the tags and indexes seperate them with , */}
<div className="text-xl">Design, Development, Branding</div>
</div>
<div className="h-screen justify-center flex flex-col space-y-3 bg-green-900 sticky top-0">
<span className="text-xl">Slemani Nwe Company</span>
<h1 className="font-semibold w-full text-5xl">
FMCG Distributer
</h1>
{/* map the tags and indexes seperate them with , */}
<div className="text-xl">Design, Development, Branding</div>
</div>
</div>
<div className="max-h-screen overflow-y-auto no-scrollbar bg-yellow-600 top-0 right-0 fixed" data-scroll-sticky>
<div className="imgs-container bg-pink-700 flex flex-col place-items-center ">
<Image
className="h-900 lg:w-10/12 xl:w-9/12 object-cover border-0 rounded-0"
src={"/projects/slemani-nwe.png"}
height={270}
width={350}
quality={100}
alt={"aa"}
priority
unoptimized
style={{
borderRadius: "0px !important",
overflow: "hidden",
}}
></Image>
<Image
className="h-900 lg:w-10/12 xl:w-9/12 object-cover border-0 rounded-0"
src={"/projects/slemani-nwe.png"}
height={270}
width={350}
quality={100}
alt={"aa"}
priority
unoptimized
style={{
borderRadius: "0px !important",
overflow: "hidden",
}}
></Image>
<Image
className="h-900 lg:w-10/12 xl:w-9/12 object-cover border-0 rounded-0"
src={"/projects/slemani-nwe.png"}
height={270}
width={350}
quality={100}
alt={"aa"}
priority
unoptimized
style={{
borderRadius: "0px !important",
overflow: "hidden",
}}
></Image>
</div>
</div>
</div>
I'm trying to figure out how to center an image (svg) in tailwind css.
<Container>
<div className="mx-auto max-w-2xl md:text-center">
<p className="justify-center">
// I have tried using center-content, text-center but get the img left aligned. How can I force it into the center of the container?
<Image src={company.logo} alt={company.name} unoptimized />
</p>
<p className="mt-4 text-lg tracking-tight text-slate-700">
{company.name}
</p>
</div>
</Container>
I can get the text for company name centered, but the image is fixed in left alignment with every variation I tried.
Your justify-center wont work if you haven't included flex.By default it display of block
<Container>
<div class="mx-auto max-w-2xl md:text-center">
<p class="flex justify-center"> // 👈 specify flex here
<image src="https://www.bing.com/th?id=OIP.o7c7ftXCLdQDsfE9NkWCvwHaGb&w=268&h=232&c=8&rs=1&qlt=90&o=6&dpr=1.3&pid=3.1&rm=2" alt="{company.name}" unoptimized />
</p>
<p class="mt-4 text-4xl tracking-tight text-slate-700">Company Here</p>
</div>
</Container>
Output:
Tailwind-css playground link
I am trying to display list images that have a fixed width and use the original height of the image that is 100%.
Similar question here with no answer.
I have read these answers here and tried them out. The images are there in the dom but out of the screen and does not show up.
The size of images varies eg. 1280x15141, 1280x14333.
This is what I am trying to do from the docs example.
<main className="mx-auto max-w-7xl ">
<section className="flex flex-col">
{chapter.images.map((img) => (
<div key={img} style={{ position: 'relative', width: '768px', height: '100%' }}>
<Image alt="Mountains" src={img} layout="fill" objectFit="contain" />
</div>
))}
</section>
</main>
This ends up displaying no image but they are present in the dom.
Update:
As per suggestion I have added height.
<section className="flex flex-col">
{chapter.images.map((img) => (
<div key={img} style={{ position: 'relative', width: '768px', height: '100px' }}>
<Image alt="Mountains" src={img} layout="fill" objectFit="contain" />
</div>
))}
</section>
Plain img tag approach.
But if i use the images in <img> instead.
I am able to see the image and apply width to it with the height as the default.
<section className="flex flex-col gap-2">
{chapter.images.map((img) => (
<div key={img} className="mx-auto md:w-4/5">
<img alt="Mountains" src={img} />
</div>
))}
</section>
But I want to use NextJs Image.
How can I do that?
I believe you're import path is incorrect
import mountains from '../../public/mountains.jpg'
I am trying to get a map of a component to go to the next line (see yellow arrow). However, right now instead of going below it is squishing the Component (the Cards). I have made bg-colors to help assist. Any guidance would be great!
<div className="border-2 h-screen bg-pink-300 ">
<div className="flex justify-end px-10 ">
<button className="border-2 border-secondary p-2 rounded-lg hover:border-opacity-20">Add Item +</button>
</div>
<div className="flex overflow-x-auto bg-green-500 ">
{data.map((data) => (
<MenuCard title={data.title} ingredients={data. ingredients}
category={data.category} onSpecial={data.onSpecial} />
))}
</div>
</div>
Add the flex-wrap class into the MenuCard's parent div element. Also remove the overflow-x-auto class as this will make the container scroll vertically.
Should look like this.
<div className="flex flex-wrap bg-green-500 ">
{data.map((data) => (
<MenuCard title={data.title} ingredients={data. ingredients}
category={data.category} onSpecial={data.onSpecial} />
))}
</div>
You might also need to add flex-shrink-0 class in each MenuCard instances if it tries to shrink.
I have been trying to make a twitter clone, while making the sidebar I am not able to align the text of "Home" and "Explore". in img you can see "Home" is little bit towards the right. while inspecting I found that faHome icon is of 18x14 size, while faHashtag is of 14x14.
I need to know how I can I keep all button's text and Icon in same alignment.
Following the code for complete screen as shown in image. I am using Tailwind CSS
<div className="flex flex-row">
{--------- Div for Nav Bar ---------}
<div class="px-4 w-80 bg-white flex flex-col justify-start align-center top-0 bottom-0 left-0 fixed">
<div>
<button className="flex p-4 bg-red-500 mb-2 rounded-full mx-auto 2xl:mx-0 2xl:space-x-4 focus:outline-none hover:text-blue hover:bg-blue hover:bg-opacity-20">
<FontAwesomeIcon icon={faHome} className="mr-4 text-xl" />
<span>Home</span>
</button>
<button className="flex p-4 bg-red-500 rounded-full mx-auto 2xl:mx-0 2xl:space-x-4 focus:outline-none hover:text-blue hover:bg-blue hover:bg-opacity-20">
<FontAwesomeIcon icon={faHashtag} className="mr-4 text-xl" />
<span>Explore</span>
</button>
<button className="flex p-4 rounded-full mx-auto 2xl:mx-0 2xl:space-x-4 focus:outline-none hover:text-blue hover:bg-blue hover:bg-opacity-20">
<FontAwesomeIcon icon={faHashtag} size="lg" className="mr-4" />
<span>Explore</span>
</button>
</div>
</div>
{---------------------}
<div className="flex-auto h-screen bg-blue-400">Hello World</div>
<div className="w-96 h-screen bg-gray-400">Hello World</div>
</div>
I want Home and explore to look something like this.
The issue was there because of icons size coming from FontAwesome Icons. though I tried to wrap the size into a div, but that didn't work.
I found out that we can use following to get the desired size of icon.
<FontAwesomeIcon icon={faHome} style={{ width: "20px", height: "230px" }} />