How to make div responsive in bootstrap?

Hi Friends 👋,

Welcome To aGuideHub! ❤️

In this article, we will use some bootstrap classes to design responsive div.

To make div responsive, put .row with col-md-6 class to create div responsive in bootstrap.

Table of contents

  • Includes bootstrap view
  • Includes bootstrap library
  • Define its class name

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 href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">

Step 3: Define its class name

After that, create div responsive with a class name .col-md-6.

    <h1 class="text-center">To make div responsive in bootstrap</h1>
    <div class="container text-white">
        <div class="row">
            <div class="col-md-6 bg-primary">Welcome To aGuideHub! ❤️</div>
            <div class="col-md-6 bg-success">Welcome To aGuideHub! ❤️</div>
        </div>
        <div class="row">
            <div class="col-md-4 bg-danger">Welcome To aGuideHub! ❤️</div>
            <div class="col-md-4 bg-info">Welcome To aGuideHub! ❤️</div>
            <div class="col-md-4 bg-danger">Welcome To aGuideHub! ❤️</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">

    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">

    <title>to make div responsive in bootstrap</title>
  </head>
  <body>
    <h1 class="text-center">To make div responsive in bootstrap</h1>
    <div class="container text-white">
        <div class="row">
            <div class="col-md-6 bg-primary">Welcome To aGuideHub! ❤️</div>
            <div class="col-md-6 bg-success">Welcome To aGuideHub! ❤️</div>
        </div>
        <div class="row">
            <div class="col-md-4 bg-danger">Welcome To aGuideHub! ❤️</div>
            <div class="col-md-4 bg-info">Welcome To aGuideHub! ❤️</div>
            <div class="col-md-4 bg-danger">Welcome To aGuideHub! ❤️</div>
        </div>
    </div>

    <!-- Option 1: Bootstrap Bundle with Popper -->
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>

    
  </body>
</html>

Check the output of the above code example.

when window size is > 576px :

Bootstrap, Table, Responsive

When window size is less than < 576px :

Bootstrap, Table, Responsive

All the best 👍