Make horizontal bootstrap 5 cards image height of the card body - html

Using Bootstrap 5.1.3, how do I get the image to be the height of the card's body & footer ?
Fixing this should also put the card-footer at the bottom of the card.
Result I'm trying to achieve:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css">
<div class="container">
<div class="card">
<div class="row g-0">
<div class="col-sm-4">
<img src="https://via.placeholder.com/150" class="h-100 card-img" alt="..."
style="object-fit: cover;">
</div>
<div class="col-sm-8">
<div class="card-body">
<h5 class="card-title">
<a class="link-dark text-decoration-none" href="#" target="_blank">Card
Title</a>
</h5>
<p class="card-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.</p>
<span class="badge rounded-pill bg-dark">Tag1</span>
</div>
<div class="card-footer text-end text-muted">
Last updated today.
</div>
</div>
</div>
</div>
</div>

I tend to avoid absolute positioning, but it works here above the mobile breakpoint. Add a few classes to do that (including on the parent element), and create a class for responsive image styles.
.fit-cover {
object-fit: cover;
}
#media (min-width: 768px) {
.fit-cover {
position: absolute;
}
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.2.0-beta1/css/bootstrap.min.css">
<div class="container">
<div class="card">
<div class="row g-0">
<div class="col-sm-4 position-relative">
<img src="https://via.placeholder.com/600" class="card-img fit-cover w-100 h-100" alt="...">
</div>
<div class="col-sm-8">
<div class="card-body">
<h5 class="card-title">
<a class="link-dark text-decoration-none" href="#" target="_blank">Card
Title</a>
</h5>
<p class="card-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.</p>
<span class="badge rounded-pill bg-dark">Tag1</span>
</div>
<div class="card-footer text-end text-muted">
Last updated today.
</div>
</div>
</div>
</div>
</div>

you asked to make > cards image height of the card body.
but according to me the content should follow the height of image.
To achieve the result as in your screen shot I have added
style="height: calc(100% - 41px);"
to card-body reducing the footer height. it will now take full height of parent element. check if this solves your problem If there anything else let me know
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.0.2/css/bootstrap.min.css">
<div class="container">
<div class="card">
<div class="row g-0">
<div class="col-sm-4">
<img src="https://via.placeholder.com/150" class="h-100 card-img" alt="..."
style="object-fit: cover;">
</div>
<div class="col-sm-8">
<div class="card-body" style="height: calc(100% - 41px);">
<h5 class="card-title">
<a class="link-dark text-decoration-none" href="#" target="_blank">Card
Title</a>
</h5>
<p class="card-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.</p>
<span class="badge rounded-pill text-bg-secondary">Tag1</span>
</div>
<div class="card-footer text-end text-muted">
Last updated today.
</div>
</div>
</div>
</div>
</div>

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.0.2/css/bootstrap.min.css">
<div class="row row-cols-1 row-cols-md-3 g-4">
<div class="col card" style="flex-direction: row;">
<div class=" h-100">
<img src="https://img.freepik.com/free-psd/futuristic-glow-t…ect-psd-editable-template_53876-115831.jpg?w=2000" class="card-img-top" alt="..." style="width: 240px;">
</div>
<div>
<div class="card-body px-2 py-2 p-0">
<h5 class="card-title">Card title</h5>
<p class="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.</p>
<div class="border-top">
<small>Update 2min ago</small>
</div>
</div>
</div>
</div>
</div>

Related

vertical align icon with text center issue Bootstrap

I have problems with center. I want to center icon and text on the same line with Bootstrap but its not working good. I am beginner here so I dont know much. Wanted this: Example https://i.stack.imgur.com/prSlD.png
My code what i have tried:
<section class="container-fluid bg-dark text-center">
<h2>WHY US</h2>
<div class="d-flex align-items-center">
<img class=" me-3" src="img/icon.png"style="width:40px" alt="">
<h5 class="mb-0">FAST DELIVERY </h5>
</div>
</section>
Try this , I think this will work
<section class='container-fluid text-center'>
<h2>WHY US</h2>
<div class='d-flex align-items-center w-100 justify-content-center'>
<img
class='me-3'
src='img/icon.png'
style='width:40px'
alt=''
/>
<h5 class='mb-0'>FAST DELIVERY </h5>
</div>
</section>
Try this one
<div class="container-fluid">
<div class="d-flex flex-column align-items-center">
<h2>WHY US ?</h2>
<div class="d-flex align-items-center gap-2">
<i class="fa-solid fa-circle-check"></i>
<h5 class="mb-0">Lorem ipsum dolor sit amet ,consectetur</h5>
</div>
<div class="d-flex align-items-center gap-2">
<i class="fa-solid fa-circle-check"></i>
<h5 class="mb-0">Lorem ipsum dolor sit amet ,consectetur</h5>
</div>
<div class="d-flex align-items-center gap-2">
<i class="fa-solid fa-circle-check"></i>
<h5 class="mb-0">Lorem ipsum dolor sit amet ,consectetur</h5>
</div>
<div class="d-flex align-items-center gap-2">
<i class="fa-solid fa-circle-check"></i>
<h5 class="mb-0">Lorem ipsum dolor sit amet ,consectetur</h5>
</div>
</div>
I have use font awesome icon you can replace it with your image tag.Hope that work for you :)

Why does my bootstrap v5 card move on vertical window resize?

Problem:
I am currently working on a website and tried my best using/learning bootstrap and wanted to implement e.g. 3 cards. But once I resized the window vertically all my elements shift upwards and it kind of destroys the look of the site, because they overlap into other elements. I think the problem might be my flex elements but I don't know how to make it work any other way.
Code:
Card elements
<section class="row container-fluid h-75 justify-content-evenly align-items-center">
<div class="col-md-3">
<div class="card text-white bg-dark p-4">
<div class="card-body">
<h5 class="card-title">Lorem ipsum dolor sit amet.</h5>
<p class="card-text">Lorem ipsum dolor sit amet consectetur adipisicing elit. Perspiciatis, natus?
</p>
Go somewhere
</div>
</div>
</div>
+2 identical cards
</section>
e.g. my footer
<footer class="container-fluid text-center py-5 text-white bg-dark">
<h1 class="pb-5">Partners:</h1>
<div class="d-lg-flex justify-content-evenly pb-5">
<img class="img-fluid w-25" src=".." alt="">
<img class="img-fluid w-25" src=".." alt="">
</div>
</footer>
Images:
Overlapping card
you can make it work by giving the margin-top on footer and to cards also,
try to run this code, if you need it like this:
<section class="row container-fluid h-75 justify-content-evenly mx-auto align-items-center">
<div class="mb-3 col-12 col-md-3">
<div class="card text-white bg-dark p-4">
<div class="card-body">
<h5 class="card-title">Lorem ipsum dolor sit amet.</h5>
<p class="card-text">
Lorem ipsum dolor sit amet consectetur adipisicing elit.
Perspiciatis, natus?
</p>
Go somewhere
</div>
</div>
</div>
+2 more identical cards
</section>
footer with mt-5
<footer class="container-fluid text-center py-5 mt-5 text-white bg-dark">
<h1 class="pb-5">Partners:</h1>
<div class="d-lg-flex justify-content-evenly pb-5">
<img class="img-fluid w-25" src=".." alt="" />
<img class="img-fluid w-25" src=".." alt="" />
</div>
</footer>

Materialize Grid Columns overflowing

I'm trying to make a "products" page, I have a card in each column, and only one row.
<section>
<div class="container">
<div class="row">
<div class="col s12">
<h4 class="grey-text text-darken-4">
New Listings
</h4>
</div>
</div>
<div class="row">
<div class="col s6 m4 l3">
<div class="card hoverable">
<a href="">
<div class="card-image">
<img src="https://source.unsplash.com/250x250/?mobile" alt="" />
</div>
<div class="card-content">
<h6 class="truncate black-text"><b>Lorem</b></h6>
<p class="truncate grey-text text-darken-2">Buy Lorem</p>
<p class="right-align grey-text"><small>Today</small></p>
</div>
</a>
</div>
</div>
<div class="col s6 m4 l3">
<div class="card hoverable">
<a href="">
<div class="card-image">
<img src="https://source.unsplash.com/250x250/?mobile" alt="" />
</div>
<div class="card-content">
<h6 class="truncate black-text"><b>Lorem</b></h6>
<p class="truncate grey-text text-darken-2">Buy Lorem</p>
<p class="right-align grey-text"><small>Today</small></p>
</div>
</a>
</div>
</div>
<div class="col s6 m4 l3">
<div class="card hoverable">
<a href="">
<div class="card-image">
<img src="https://source.unsplash.com/250x250/?mobile" alt="" />
</div>
<div class="card-content">
<h6 class="truncate black-text"><b>Lorem</b></h6>
<p class="truncate grey-text text-darken-2">Buy Lorem</p>
<p class="right-align grey-text"><small>Today</small></p>
</div>
</a>
</div>
</div>
</div>
</div>
</section>
My code looks something like this, a card jumps from one line to the next even though there is space for it, I don't really know what is wrong
Edit: It is working now, gave a class "small" to card div. Thanks to Sean.
Materialize rows don't handle cards with different heights very well, for this scenario, it helps to fix the height of your cards to make them uniform using the three provided classes:|
<div class="card small">
<!-- Card Content -->
</div>
Three sizes applied as an extra class on the card - small, medium and large which equate to:
.card.small {
height: 300px;
}
.card.medium {
height: 400px;
}
.card.large {
height: 500px;
}
https://materializecss.com/cards.html#sizes

How to add gap between cards

I need space between the cards as shown in the picture, how do I add spacing so that structure remains the same
<div class="container" style="padding: 16px;">
<div class="row">
<div class="center">
<div class="card text-white bg-primary mb-r" style="width:100px;height:100px;margin: auto;">
<div class="card-body">
<h4 class="card-title">DEL</h4>
<h7 class="card-text" style="align-content:flex-end">916</h7>
</div>
</div>
</div>
<div class="center">
<div class="card text-white bg-primary mb-r" style="width:100px;height:100px;margin: auto;">
<div class="card-body">
<h4 class="card-title">DEL</h4>
<h7 class="card-text" style="align-content:flex-end">916</h7>
</div>
</div>
</div>
<div class="center">
<div class="card text-white bg-primary" style="width:100px;height:100px;margin: auto;">
<div class="card-body">
<h4 class="card-title">DEL</h4>
<h7 class="card-text" style="align-content:flex-end">916</h7>
</div>
</div>
</div>
<div class="center">
<div class="card text-white bg-primary" style="width:100px;height:100px;margin: auto;">
<div class="card-body">
<h4 class="card-title">DEL</h4>
<h7 class="card-text" style="align-content:flex-end">916</h7>
</div>
</div>
</div>
</div>
</div>
The picture below is the code I have written, I need spacing between them.
To have spacing between cards just use standard Bootstrap layout, that is using row and columns. Columns have gutters by default. Read more: https://getbootstrap.com/docs/4.3/layout/overview/
There were many errors like <h7> tags, using incorrect css properties etc. Just go through my code and see the changes I made.
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<div class="container">
<div class="row">
<div class="col-3">
<div class="card w-100 text-white bg-primary">
<div class="card-body">
<h4 class="card-title">DEL</h4>
<h6 class="card-text">916</h6>
</div>
</div>
</div>
<div class="col-3">
<div class="card w-100 text-white bg-primary">
<div class="card-body">
<h4 class="card-title">DEL</h4>
<h6 class="card-text">916</h6>
</div>
</div>
</div>
<div class="col-3">
<div class="card w-100 text-white bg-primary">
<div class="card-body">
<h4 class="card-title">DEL</h4>
<h6 class="card-text">916</h6>
</div>
</div>
</div>
<div class="col-3">
<div class="card w-100 text-white bg-primary">
<div class="card-body">
<h4 class="card-title">DEL</h4>
<h6 class="card-text">916</h6>
</div>
</div>
</div>
</div>
</div>
I know you asked that the structure didn't change however I believe some edits needed to be made, here is a jsFiddle with some suggestions: https://jsfiddle.net/kcozqd9L/2/
CSS
.container{
padding: 16px;
}
.card{
position: relative;
display: inline-block;
width:100px;
height:100px;
margin: auto;
}
/*.card-body{
}
.card-title{
}*/
.card-text{
align-content:flex-end
}
HTML
<!--
Bootstrap docs: https://getbootstrap.com/docs
-->
<div class="container">
<div class="row">
<div class="center">
<div class="card text-white bg-primary mb-r">
<div class="card-body">
<h4 class="card-title">DEL</h4>
<h6 class="card-text">916</h6>
</div>
</div>
<div class="card text-white bg-primary mb-r">
<div class="card-body">
<h4 class="card-title">DEL</h4>
<h6 class="card-text">916</h6>
</div>
</div>
<div class="card text-white bg-primary">
<div class="card-body">
<h4 class="card-title">DEL</h4>
<h6 class="card-text">916</h6>
</div>
</div>
<div class="card text-white bg-primary">
<div class="card-body">
<h4 class="card-title">DEL</h4>
<h6 class="card-text">916</h6>
</div>
</div>
</div>
</div>
</div>

Bootstrap Cards Not Shifting Down

I am trying to get some help with my bootstrap cards. I have 4 cards which extend horizontally across the whole width of the page. When visiting the website on a mobile device they stay all still extend horizontally and then stretch vertically. I would like them to stay one on top of another. Help would be appreciated. Thanks.
Pictures: https://imgur.com/a/W65324F
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous" />
<div class="row">
<div class="col-sm-4 my-4" style="max-width:25% !important;">
<div class="card">
<img class="card-img-top" src="/images/personal/harris.jpeg" alt="">
<div class="card-body">
<h4 class="card-title">Bill Harris</h4>
<h6 class="card-subtitle mb-2 text-muted">Counselor</h6>
<p class="card-text">Mr. Harris is going to be Maui for Halloween!</p>
</div>
<div class="card-footer">
Find Out More!
</div>
</div>
</div>
<div class="col-sm-4 my-4" style="max-width:25% !important;">
<div class="card">
<img class="card-img-top" src="/images/personal/smiegel.jpeg" alt="">
<div class="card-body">
<h4 class="card-title">Emily Smigel</h4>
<h6 class="card-subtitle mb-2 text-muted">Counselor</h6>
<p class="card-text">Ms. Smigel is a Fullstack Developer.</p>
</div>
<div class="card-footer">
Find Out More!
</div>
</div>
</div>
<div class="col-sm-4 my-4" style="max-width:25% !important;">
<div class="card">
<img class="card-img-top" src="/images/personal/krzyminski.jpeg" alt="">
<div class="card-body">
<h4 class="card-title">Marcy Krzyminski</h4>
<h6 class="card-subtitle mb-2 text-muted">Secretary</h6>
<p class="card-text">Ms. Krzyminski is a computer repair technician.</p>
</div>
<div class="card-footer">
Find Out More!
</div>
</div>
</div>
<div class="col-sm-4 my-4" style="max-width:25% !important;">
<div class="card">
<img class="card-img-top" src="http://placehold.it/550x550" alt="">
<div class="card-body">
<h4 class="card-title">Patti Walther</h4>
<h6 class="card-subtitle mb-2 text-muted">Secretary</h6>
<p class="card-text">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sapiente esse necessitatibus neque.</p>
</div>
<div class="card-footer">
Find Out More!
</div>
</div>
</div>
</div>
To adjust the number of columns items will take up in Bootstrap, use media queries and col-X-n where X is screen size in xs, sm, etc. and n is number of columns (1-12).
In your case, adding the class col-xs-6 will make it so your 4-column layout breaks into 2 columns at smaller widths. col-xs-12 would instead give you 1 column.
Here's the Bootstrap responsive breakpoint reference for good measure!
You can use flexbox and media queries to solve this:
#media (max-width: 600px) {
.row{
display: flex;
flex-direction: column;
}
}
where .row is the container of the cards