Bootstrap Cards Not Shifting Down - html

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

Related

In bootstrap how do I make my card div responsive?

The section I am doing is just 6 cards, 3 cards in a row of 2. When the screen goes to small (mobile phone size) I want each card just to be on their own row. Each card showing one by one as the user scrolls.
It functions this way when I resize the screen however, when I go to google tools, it does not show my desired outcome.
.row {
padding: 4rem;
background-color: #F8F8FF;
border: 4px black;
colour: red;
}
.card {
background-color: #ddf;
padding: 30px;
margin: 20px;
transition: 0.40s;
}
.card:hover {
transform: scale(1.05);
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.2/dist/css/bootstrap.min.css" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<div class="container ">
<h1 class="display-4">My Projects/Work</h1>
<div class="row g-3">
<div class="col-12 col-md-6 col-lg-4">
<div class="card" id="proj1">
<img src="https://via.placeholder.com/300x200" class="card-img-top" alt="project_1" />
<div class="card-body">
<h5 class="card-title">Blog Project</h5>
<p class="card-text">
A simple blog website which I made from scratch using html , css and javascript for the frontend.The backend was done with Django and SQL.
</p>
Click to see
</div>
</div>
</div>
<div class="col-12 col-md-6 col-lg-4">
<div class="card" id="proj2">
<img src="https://via.placeholder.com/300x200" class="card-img-top" alt="project_2" />
<div class="card-body">
<h5 class="card-title">Social media clone </h5>
<p class="card-text">
A social media clone with all the main features of a social media site such as Facebook.In order to achieve this I used Django and React.
</p>
Click to see
</div>
</div>
</div>
<div class="col-12 col-md-6 col-lg-4">
<div class="card" id="proj3">
<img src="https://via.placeholder.com/300x200" class="card-img-top" alt="project_3" />
<div class="card-body">
<h5 class="card-title">E-commence site</h5>
<p class="card-text">
This is a website I build for a small tech company in my local area that specialized in databases .
</p>
Click to see
</div>
</div>
</div>
</div>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.2/dist/css/bootstrap.min.css" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<div class="container">
<div class="row">
<div class="col-12 col-md-6 col-lg-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text.</p>
</div>
</div>
</div>
<div class="col-12 col-md-6 col-lg-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text.</p>
</div>
</div>
</div>
<div class="col-12 col-md-6 col-lg-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text.</p>
</div>
</div>
</div>
<div class="col-12 col-md-6 col-lg-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text.</p>
</div>
</div>
</div>
<div class="col-12 col-md-6 col-lg-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text.</p>
</div>
</div>
</div>
<div class="col-12 col-md-6 col-lg-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text.</p>
</div>
</div>
</div>
</div>
</div>
You can put classes on "row" or "column" https://getbootstrap.com/docs/4.6/utilities/flex/#align-items
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.2/dist/css/bootstrap.min.css" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<section class="bg-light pt-5 pb-5 shadow-sm">
<div class="container">
<div class="row pt-5">
<div class="col-12">
<h3 class="text-uppercase border-bottom mb-4">Bootstrap Responsive</h3>
</div>
</div>
<div class="row">
<div class="col-lg-4 mb-3 d-flex align-items-stretch">
<div class="card">
<img src="https://via.placeholder.com/300x200" class="card-img-top" alt="Card Image">
<div class="card-body d-flex flex-column">
<h5 class="card-title">Blog Project</h5>
<p class="card-text mb-4">A simple blog website which I made from scratch using html , css and javascript for the frontend.The backend was done with Django and SQL.</p>
Click to see
</div>
</div>
</div>
<div class="col-lg-4 mb-3 d-flex align-items-stretch">
<div class="card">
<img src="https://via.placeholder.com/300x200" class="card-img-top" alt="Card Image">
<div class="card-body d-flex flex-column">
<h5 class="card-title">Blog Project</h5>
<p class="card-text mb-4">A simple blog website which I made from scratch using html , css and javascript for the frontend.The backend was done with Django and SQL.</p>
Click to see
</div>
</div>
</div>
<div class="col-lg-4 mb-3 d-flex align-items-stretch">
<div class="card">
<img src="https://via.placeholder.com/300x200" class="card-img-top" alt="Card Image">
<div class="card-body d-flex flex-column">
<h5 class="card-title">Blog Project</h5>
<p class="card-text mb-4">A simple blog website which I made from scratch using html , css and javascript for the frontend.The backend was done with Django and SQL.</p>
Click to see
</div>
</div>
</div>
</div>
</div>
</section>

Make horizontal bootstrap 5 cards image height of the card body

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>

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>

How to size the image in equal length in bootstrap card

<!--........PORTFOLIO..........-->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<section class="portfolio bg-light">
<div class="container-fluid text-center">
<h1>PORTFOLIO</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Adipisci, voluptates.</p>
<div class="row">
<div class="col-lg-4 col-md-4 col-sm-12 col-10 d-block m-auto">
<div class="card">
<img src="Resposive.jpg" class="card-img img-fluid">
<div class="card-body">
<h2 class="card-title">Threads</h2>
<p class="card-text">Illustration</p>
</div>
</div>
</div>
<div class="col-lg-4 col-md-4 col-sm-12 col-10 d-block m-auto">
<div class="card">
<img src="booking1.jpg" class="card-img img-fluid">
<div class="card-body">
<h2 class="card-title">Threads</h2>
<p class="card-text">Illustration</p>
</div>
</div>
</div>
<div class="col-lg-4 col-md-4 col-sm-12 col-10 d-block m-auto">
<div class="card">
<img src="Resposive.jpg" class="card-img img-fluid">
<div class="card-body">
<h2 class="card-title">Threads</h2>
<p class="card-text">Illustration</p>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
how to size the image equally in bootstrap4 card system as i am using the images of different size so by this the card size is also increasing .
please help me out from this as i am not able to size the cards in equal manner as i am using grid system .
you canheight to you images with !important to prevent override. and set object-fit: cover;:
.card-img{
width: 100%!important;
height: 200px!important;
object-fit: cover;
}
see fiddle:https://jsfiddle.net/dhupq0m4/
you can use media-query to change width/height
media-query: https://www.w3schools.com/css/css3_mediaqueries_ex.asp
Card size is not equal because it has not equal size content or equal size images. Force the image to be in equal height with "height" or you can crop images into equal height. Having image with equal height good because it will not destroy the look of image. If you force the image to take height then you will not have a good image look.

How to add padding in between cards in bootstrap

I have a row consisting of 8 cards.
I want to have all these in single line.
There is a margin of column size 2 on left side and I have set each card of size 1 (so 8 + 2 = 10)
But then, my row is all messed up.
Currently my code for border is
<div class="row">
<div class="col-sm-2">
<div class="card-header"> Discover new genres {{genre}}</div>
</div>
<div class="col-lg-1 text-center">
<div class="card border-secondary mb-3" style="width: 10rem;">
<img class="card-img-top img-responsive full-width circle-img rounded-circle" src="{{rec['artpath']}}" alt="{{rec['name']}}">
</img>
<div class="card-block">
<div class="card-body"><p class="card-title text-center "><small>{{rec["name"]}}</small></p></div>
</div>
</div>
</div>
</div>
I want the card to have this width (so not card to be small)..It can overflow on the right side of the screen..
How do i do this?
The problem has to do with your inline style of width:10rem. It's going to supersede the width of col-lg-1 when it is greater than that column width. Removing this inline style results in expected behavior.
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
<div class="container-fluid">
<div class="row">
<div class="col-4">
<div class="card-header"> Discover new genres {{genre}}</div>
</div>
<div class="col-4 text-center">
<div class="card border-secondary mb-3" style="">
<img class="card-img-top img-responsive full-width circle-img rounded-circle" src="{{rec['artpath']}}" alt="{{rec['name']}}">
<div class="card-block">
<div class="card-body">
<p class="card-title text-center">
<small>{{rec["name"]}}</small>
</p>
</div>
</div>
</div>
</div>
<div class="col-4 text-center">
<div class="card border-secondary mb-3" style="">
<img class="card-img-top img-responsive full-width circle-img rounded-circle" src="{{rec['artpath']}}" alt="{{rec['name']}}">
<div class="card-block">
<div class="card-body">
<p class="card-title text-center">
<small>{{rec["name"]}}</small>
</p>
</div>
</div>
</div>
</div>
</div>
</div>
For the purposes of this example I've changed your column breakpoints to something that works better when you choose 'Run Code Snippet'. I suspect you were applying an inline width because col-lg-1 is too small; that being the case I recommend you consider a larger column breakpoint in lieu of inline styles overriding grid behavior.