How to give space between two vertical div in bootstrap?

Hi Friends 👋,

Welcome To aGuideHub! ❤️

In this tutorial, we will learn how to give space between two vertical div in bootstrap.

To give space between two vertical div, put .margin-top: 2em class to create space in two vertical div.

Table of contents

  • Includes bootstrap view
  • Includes bootstrap library
  • Includes css in html page
  • 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">   

Step 2: Includes bootstrap library

First of all, load the Bootstrap framework CSS into the head tag of your webpage.

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

Step 3: Includes css in html page

Here we are using in css class to add give space between vertical div.

   .vertical{
        width: 100%;
        height: 100%;
        background-color: #9242e2;
        margin: auto;
        margin-top: 2em;
    }

Step 4: Define its class name

After that, create space between vertical div with a class name .vertical.

   <h2>Space between two vertical div in bootstrap</h2>
    <div style="width:100%;">
        <div class="vertical">
            aGuideHub
        </div>
        <div class="vertical">
            aGuideHub
        </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>Bootstrap</title>
<style>
   .vertical{
        width: 100%;
        height: 100%;
        background-color: #9242e2;
        margin: auto;
        margin-top: 2em;
    }
  
</style>
</head>

<body>

    <h2>Space between two vertical div in bootstrap</h2>
    <div style="width:100%;">
        <div class="vertical">
            aGuideHub
        </div>
        <div class="vertical">
            aGuideHub
        </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.

Bootstrap, vertical-div

All the best 👍