How to make button responsive in bootstrap 4?
June 15, 2022Hi Friends 👋,
Welcome To aGuideHub! ❤️
In this article, we will use some bootstrap 4 classes to make button responsive.
To make button respnonsive, put row and col-md-10
with btn
class to make button responsive in bootstrap 4.
Table of contents
- Includes bootstrap 4 view
- Includes bootstrap 4 library
- Define its class name
Step 1: Includes bootstrap 4 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 4 library
First of all, load the Bootstrap 4 framework CSS into the head tag of your webpage.
<!-- Bootstrap CSS -->
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
Step 3: Define its class name
After that, create responsive button with a class name .btn
.
<div class="container-fluid">
<div class="row text-center">
<div class="col-10 offset-1">
<button class="btn btn-primary ">Select All Items</button>
<button class="btn btn-primary ">Unselect All Items</button>
<button class="btn btn-primary ">New Items</button>
</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">
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container-fluid">
<div class="row text-center">
<div class="col-10 offset-1">
<button class="btn btn-primary ">Select All Items</button>
<button class="btn btn-primary ">Unselect All Items</button>
<button class="btn btn-primary ">New Items</button>
</div>
</div>
</div>
</div>
</body>
</html>
Check the output of the above code example.
All the best 👍