Custom deck of card in bootstrap 4 - html

How to create this card grid inside container(Bootstrap 4)?
I doesn't understand how i can put text in container if text in div(card).
<section class="second__offers">
<div class="container">
<div class="card-group">
<div class="card text-black">
<img class="card-img-top" src="img/service-1.jpg" alt="Card image top">
<div class="card-img-overlay">
<h3 class="card-title">Card title</h3>
<h4 class="card-subtitle">Card subtitle</h4>
<p class="card-text">This is a simple Card example</p>
About
</div>
</div>
<div class="card text-black">
<img class="card-img-top" src="img/service-2.jpg" alt="Card image top">
<div class="card-img-overlay">
<h3 class="card-title">Card title</h3>
<p class="card-text">This is a simple Card example</p>
About
</div>
</div>
<div class="card text-black">
<img class="card-img-top" src="img/service-3.jpg" alt="Card image top">
<div class="card-img-overlay">
<h3 class="card-title">Card title</h3>
<p class="card-text">This is a simple Card example</p>
About
</div>
</div>
</div>
<div class="card-group">
...
</div>
</div>
</section>
example:

Use background-image: instead of img tag (add class to each card and in css and the fit background-image:)
To your comment make container take 100% of width use container-fluid instead of container and set in css:
.container-fluid{
padding:0!important;
margin:0!important;
}
https://jsfiddle.net/nhybo32s/10/
.face{
background-image: url(https://material.angular.io/assets/img/examples/shiba1.jpg);
background-repeat: no-repeat;
background-size: 100% 100%;
}
.body{
background-image: url(https://material.angular.io/assets/img/examples/shiba2.jpg);
background-repeat: no-repeat;
background-size: 100% 100%;
}
.card {border:none!important}
.container-fluid{
padding:0!important;
margin:0!important;
}
<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="second__offers">
<div class="container-fluid">
<div class="card-group">
<div class="card text-black face">
<div class="">
<h3 class="card-title">Card title</h3>
<h4 class="card-subtitle">Card subtitle</h4>
<p class="card-text">This is a simple Card example</p>
About
</div>
</div>
<div class="card text-black body">
<div>
<h3 class="card-title">Card title</h3>
<p class="card-text">This is a simple Card example</p>
About
</div>
</div>
<div class="card text-black">
<div>
<h3 class="card-title">Card title</h3>
<p class="card-text">This is a simple Card example</p>
About
</div>
</div>
</div>
<div class="card-group">
...
</div>
</div>
</section>

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>

How to minimize Card spacing in Bootstraps 4

I just created 4 card using bootstraps 4.5 version but the spacing is really bad and I do not know how to reduce the spacing of card you can the image if you still confuse
.card {
width : 55%;
min-height: 100;
margin: 2%;
}
.card-img-top {
height: 150px;
object-fit: cover;
}
.card-body{
box-shadow: 0 0 20px 7px rgba(0,0,0,0.1);
}
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="card text-md-center">
<img src="Nike.jpg" class="card-img-top">
<div class="card-body">
<h5 class="card-title">Shoes</h5>
<p class="card-text">Some quick example text</p>
Buy
</div>
</div>
</div>
<div class="col-md-4">
<div class="card text-md-center">
<img src="chevrolet.jpg" class="card-img-top">
<div class="card-body">
<h5 class="card-title">Car</h5>
<p class="card-text">Some quick example text</p>
Buy
</div>
</div>
</div>
<div class="col-md-4">
<div class="card text-md-center">
<img src="asuslap.jpg" class="card-img-top">
<div class="card-body">
<h5 class="card-title">Laptop</h5>
<p class="card-text">Some quick example text</p>
Buy
</div>
</div>
</div>
<div class="col-md-4">
<div class="card text-md-center">
<img src="asusphone.jpg" class="card-img-top">
<div class="card-body">
<h5 class="card-title">Phone</h5>
<p class="card-text">Some quick example text</p>
Buy
</div>
</div>
</div>
</div>
I have searched it in google but I still not find it (How to reduce spacing of Card), maybe you can help me
If you don't problem about the width card, you can remove width : 55%; in your CSS. It would be better.
OR
You can change the value in every col-md class. The spacing the of every card is caused by that.
I added a flex-display to your .row class and justified everything in the center. Spacing looks fine to me.
.card {
width: 55%;
min-height: 100;
margin: 2%;
}
.card-img-top {
height: 150px;
object-fit: cover;
}
.card-body{
box-shadow: 0 0 20px 7px rgba(0,0,0,0.1);
}
.row {
display: flex;
justify-content: center;
}
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="card text-md-center">
<img src="Nike.jpg" class="card-img-top">
<div class="card-body">
<h5 class="card-title">Shoes</h5>
<p class="card-text">Some quick example text</p>
Buy
</div>
</div>
</div>
<div class="col-md-4">
<div class="card text-md-center">
<img src="chevrolet.jpg" class="card-img-top">
<div class="card-body">
<h5 class="card-title">Car</h5>
<p class="card-text">Some quick example text</p>
Buy
</div>
</div>
</div>
<div class="col-md-4">
<div class="card text-md-center">
<img src="asuslap.jpg" class="card-img-top">
<div class="card-body">
<h5 class="card-title">Laptop</h5>
<p class="card-text">Some quick example text</p>
Buy
</div>
</div>
</div>
The Bootstrap way to do so is to dynamically adjust the column width depending on the width of the browser/screen. Do not set the width manually. Let the media query breakpoints do the job.
HTML
<div class="container">
<div class="row">
<div class="col-6 col-md-4 col-lg-3">
<div class="card text-md-center">
<img src="http://placehold.jp/320x180.png" class="card-img-top">
<div class="card-body">
<h5 class="card-title">Shoes</h5>
<p class="card-text">Some quick example text</p>
Buy
</div>
</div>
</div>
<div class="col-6 col-md-4 col-lg-3">
<div class="card text-md-center">
<img src="http://placehold.jp/320x180.png" class="card-img-top">
<div class="card-body">
<h5 class="card-title">Car</h5>
<p class="card-text">Some quick example text</p>
Buy
</div>
</div>
</div>
<div class="col-6 col-md-4 col-lg-3">
<div class="card text-md-center">
<img src="http://placehold.jp/320x180.png" class="card-img-top">
<div class="card-body">
<h5 class="card-title">Laptop</h5>
<p class="card-text">Some quick example text</p>
Buy
</div>
</div>
</div>
<div class="col-6 col-md-4 col-lg-3">
<div class="card text-md-center">
<img src="http://placehold.jp/320x180.png" class="card-img-top">
<div class="card-body">
<h5 class="card-title">Phone</h5>
<p class="card-text">Some quick example text</p>
Buy
</div>
</div>
</div>
</div>
CSS
.card {
/* width: 55%; */
min-height: 100;
margin: 2%;
}
.card-img-top {
height: 150px;
object-fit: cover;
}
.card-body {
box-shadow: 0 0 20px 7px rgba(0, 0, 0, 0.1);
}
JSFiddle demo

flex item being pushed out of containing div (off screen)

I am trying to build a responsive website.
and I want all of my divs to always be in the middle.
for some reason when I use flex attribute in my container the bootstrap card go offscreen:
any suggestions on how to handle it right?
Normal Screen
Normal
Moblie Screen :(
Mobile
My HTML CODE
<body>
<div class="container">
<div class="d-flex justify-content-center align-items-center">
<form action="" method="POST">
{% csrf_token %}
<div id="smain">
<h1> Lets Start</h1>
<div class="card-deck">
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="{% static "/images/pc.jpg" %}" alt="Card image cap">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title bulk of the
card's content.</p>
Go somewhere
</div>
</div>
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="{% static "/images/dance.png" %}" alt="Card image cap">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example
text to build on the card title and makecontent.
</p>
<a href="#" class="btn btn-primary">Go
somewhere</a>
</div>
</div>
</div>
</div>
</form>
</div>
CSS
body {
background-image: url("{% static "images/unnamed1.jpg" %}");
background-size: cover;
background-repeat: no-repeat;
}
html,
body {
height: 100%;
}
.container {
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
Use margin on the children instead of justify-content: center; on the parent.
html,
body {
height: 100%;
}
.container {
height: 100%;
display: flex;
}
.container>div{
margin:auto;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css">
<div class="container">
<div class="d-flex justify-content-center align-items-center">
<form action="" method="POST">
<div id="smain">
<h1> Lets Start</h1>
<div class="card-deck">
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="https://picsum.photos/300/500" images="" pc.jpg "=" " %}"="" alt="Card image cap">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title bulk of the card's content.</p>
Go somewhere
</div>
</div>
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="https://picsum.photos/300/500" images="" dance.png "=" " %}"="" alt="Card image cap">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and makecontent.
</p>
<a href="#" class="btn btn-primary">Go
somewhere</a>
</div>
</div>
</div>
</div>
</form>
</div>
</div>

How can I create the following Bootstrap Component?

I am trying to create the following component using Bootstrap
What I tried:
<style>
.card-container {
height:150px;
overflow-y: scroll;
}
</style>
<div class="jumbletron">
<div class="card card-inverse">
<div class="card-block">
<h3 class="card-title text">Alerts Card</h3>
<div class="card-container">
<div class="card card-inverse">
<div class="card-block">
<h3 class="card-title text">Alert 1</h3>
</div>
</div>
</div>
<div class="card card-inverse">
<div class="card-block">
<h3 class="card-title text">Alert 2</h3>
</div>
</div>
</div>
</div>
</div>
http://jsfiddle.net/rp51o4se/1/
But unfortunately couldn't figure out a way how to properly do it. How can I accomplish this?
In your example you used jumbletron instead of jumbotron for the class and place one of the cards outside the container.
Updated example here - http://jsfiddle.net/rp51o4se/5/
I also added a padding of 1rem to the card container to make it closer to your attached image.
You have your divs a bit mixed up and not wrapping properly.
.card-container {
height:150px;
overflow-y: scroll;
}
<div class="jumbotron">
<h1>My alert center</h1>
<div class="card-container">
<div class="card card-inverse">
<div class="card-body">
<h3 class="card-title text">Alerts Card</h3>
</div>
</div>
<div class="card card-inverse">
<div class="card-body">
<h3 class="card-title text">Alert 1</h3>
</div>
</div>
<div class="card card-inverse">
<div class="card-body">
<h3 class="card-title text">Alert 2</h3>
</div>
</div>
</div>
</div>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css">
</head>
<style>
.jumbotron{
height: 200px;
overflow-y: scroll;
}
.mb-10{
margin-bottom: 20px;
}
</style>
<body>
<div class="jumbotron">
<div class="card-container">
<div class="card w-50 mb-10">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
</div>
</div>
<div class="card w-50 mb-10">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
</div>
</div>
<div class="card w-50 mb-10">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
</div>
</div>
</div></div>
</body>
</html>
Try this

Bootstrap 4 .card-group not applying to cards within columns

I want to create a card group of 3 cards that each should be 4 columns wide. How do I achieve this and keep .card-group working to make them all the same height?
<div class="row">
<div class="card-group">
<div class="col-md-4">
<div class="card">
<img class="card-img-top" src="http://lorempixel.com/400/200/">
<div class="card-block">
<h4 class="card-title">Card title</h4>
<p class="card-text">Card text</p>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<img class="card-img-top" src="http://lorempixel.com/400/200/">
<div class="card-block">
<h4 class="card-title">Card title</h4>
<p class="card-text">Card text</p>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<img class="card-img-top" src="http://lorempixel.com/400/200/">
<div class="card-block">
<h4 class="card-title">Card title</h4>
<p class="card-text">Card text</p>
</div>
</div>
</div>
</div>
Remove your divs that declare the col-md-4 class. Card groups and decks are built to auto size your cards width, and will space them evenly automatically.
Check out the sample block for groups from the official documentation if you want to see an example.