How to give space between two cards in bootstrap?
June 02, 2022Hi Friends 👋,
Welcome To aGuideHub! ❤️
In this tutorial, we will learn how to give space between two cards in bootstrap.
To give space between two cards, put .card .col-lg-6 mb-4
make in bootstsrap.
The card component support a wide variety of content, including images, text, list groups, links, navs, and more. Cards have no specific width, they are 100% wide by default. However, you can change this as needed with custom CSS, grid classes, or sizing utility classes.
This example using bootstrap’s grid to make a row and space it.
Table of contents
- Includes bootstrap view
- Includes bootstrap library
- Includes css in html page
- Define its class name
Here are the examples of what’s supported by the card.
Step 1: Includes bootstrap view
To ensure proper rendering and touch zooming for all devices, add the responsive viewport meta tag to your <head>
.
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
Step 2: Includes bootstrap library
First of all, load the Bootstrap framework CSS into the head tag of your webpage.
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.4.1/css/all.css"
integrity="sha384-5sAR7xN1Nv6T6+dT2mhtzEpVJvfS3NScPQTrOxhwjIuvcA67KV2R5Jz6kr4abQsz" crossorigin="anonymous">
Step 4: Define its class name
After that, create space between two cards with a class name .card .col-lg-6 mb-4
.
<div class="container">
<div class="row">
<div class="col-lg-6 mb-4">
<div class="card">
<img class="card-img-top" src="image/autumn-poolside.jpg" alt="">
<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 make up the bulk
of the card's content.
</p>
<a href="#" class="btn btn-primary btn-sm">
Card link
</a>
<a href="#" class="btn btn-secondary btn-sm">
<i class="far fa-heart"></i></a>
</div>
</div>
</div>
<div class="col-lg-6 mb-4">
<div class="card">
<img class="card-img-top" src="image/autumn-poolside.jpg" alt="">
<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 make up the bulk of the
card's content.
</p>
<a href="#" class="btn btn-outline-primary btn-sm">
Card link
</a>
<a href="#" class="btn btn-outline-secondary btn-sm">
<i class="far fa-heart"></i></a>
</div>
</div>
</div>
</div>
</div>
Example.
Let’s look at the following example to understand how it basically works:
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,
initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.4.1/css/all.css"
integrity="sha384-5sAR7xN1Nv6T6+dT2mhtzEpVJvfS3NScPQTrOxhwjIuvcA67KV2R5Jz6kr4abQsz" crossorigin="anonymous">
<title>
</title>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-lg-6 mb-4">
<div class="card">
<img class="card-img-top" src="image/autumn-poolside.jpg" alt="">
<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 make up the bulk
of the card's content.
</p>
<a href="#" class="btn btn-primary btn-sm">
Card link
</a>
<a href="#" class="btn btn-secondary btn-sm">
<i class="far fa-heart"></i></a>
</div>
</div>
</div>
<div class="col-lg-6 mb-4">
<div class="card">
<img class="card-img-top" src="image/autumn-poolside.jpg" alt="">
<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 make up the bulk of the
card's content.
</p>
<a href="#" class="btn btn-outline-primary btn-sm">
Card link
</a>
<a href="#" class="btn btn-outline-secondary btn-sm">
<i class="far fa-heart"></i></a>
</div>
</div>
</div>
</div>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous">
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous">
</script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous">
</script>
</body>
</html>
Check the output of the above code example.
All the best 👍