user16616459
user16616459

Reputation: 21

How to remove the whitespace between two columns of a row in bootstrap 5 grid?

I am trying to achieve the grid layout given below enter image description here

.col_1{
    background-color: bisque !important;
    height: 500px;

  
}
.col_2 {
    width: 300px;
    height: 287px;
    background-position: center;
    background-image: url('https://images.unsplash.com/photo-1633113218833-f0b9912cfe1c?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1170&q=80');
}
.col_3{
    width: auto;
    height: 280px;
    background-color: blue;
    /* margin: 0 !important; */
}
.col_4{
    width: auto;
    height: 300px;
    background-color: yellowgreen;

}
.col_5{
    width: auto;
    height: 350px;
    background-color: black;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Practice 1</title>
     <link  href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
</head>
<body>
    <div class="container mt-2">
<div class="row">  
    <div class="col-sm-4 col_1"> 
        <div class="col col-sm-3 col_1"></div>
    </div> 
    <div class="col-sm-8">
        <div class="container-fluid">
        <div class="row">
                    <div class="col col-md-6 col-md-2">
                            <div class="col col-sm-6 col_2"></div>
                            <div class="col col-sm-6 mt-2 col_3"></div>
           
                </div>
                    <div class="col col-md-6">
                            <div class="col col-sm-6 col_4"></div>
                            <div class="col col-sm-6 mt-2 col_5"></div>
                 
                </div>
            </div>
        </div>
        </div>
    </div>

</div>
    </body>
</html>
So the first The Problem I am facing is that when I reduce the width of the image whitespace comes between the image and its adjacent column. If I keep the width of all columns auto then the whitespace does not appear.
I inspected my code and I found the margin on the right side of the column which is leading to the whitespace I am also posting my inspected webpage belowenter image description here

So how can I fix this issue of whitespace? Or only solution to this is using position relative and margin?

Upvotes: 0

Views: 303

Answers (1)

Miran
Miran

Reputation: 33

try use background-repeat,background-size

.col_2 {
    width: 300px;
    height: 287px;
    background-position: center;
    background-repeat: no-repeat;
    background-size:100%;
    background-image: url('https://images.unsplash.com/photo-1633113218833-f0b9912cfe1c?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1170&q=80');
}

Upvotes: 2

Related Questions