0

This is my code for CSS Column

<div id="a">
    <div class="b"></div>
    <div class="b" style="height:30px;"></div>
    <div class="b" style="height:30px;"></div>
    <div class="b"></div>
    <div class="b"></div>
    <div class="b"></div>
</div>
<style>
    #a {
        position: relative;
        display: block;
        background:yellow;
        width:500px;
    }

    .b {
        background:pink;
        width: 40%;
        display: inline-block;
        height:50px;
        vertical-align: top;
        margin:10px;
    }
</style>

This is the column that i want to: enter image description here

how to remove the vertical gap between each column. enter image description here

Techie_T
  • 415
  • 3
  • 14
My real name
  • 535
  • 1
  • 5
  • 17

2 Answers2

0

Remove the style attribute from

 <div class="b" style="height:30px;"></div>
 <div class="b" style="height:30px;"></div>

And set margin to something less, like 3px

EDIT: if you need to change height, you need to adopt a different approach to the problem. See below.

.a {
  display: inline-block;
  background: yellow;
  width: 500px;
  width: 40%;
}

.b {
  background: pink;
  vertical-align: top;
  margin: 3px;
}

.container {
  display: inline-block;
}
<div class="contaisner">
  <span class="a">
   <div class="b">a<br>a<br>a<br>a<br></div>
   <div class="b">a<br>a<br>a<br></div>
   <div class="b">a<br>a<br>a<br>a<br></div>
  </span>
  <span class="a">
   <div class="b">a<br>a<br>a<br></div>
   <div class="b">a<br>a<br>a<br>a<br></div>
   <div class="b">a<br>a<br>a<br>a<br></div>
  </span>
</div>

This should be close enough

athi
  • 1,683
  • 15
  • 26
Donny
  • 516
  • 3
  • 9
-1

You can give column-count to the outer div and add outer div to the child element. break-inside: avoid; should be given to the child elements.

<div id="a">
  <div class="b">
    <div></div>
  </div>
  <div class="b" style="height:30px;">
    <div></div>
  </div>
  <div class="b" style="height:30px;">
    <div></div>
  </div>
  <div class="b">
    <div></div>
  </div>
  <div class="b">
    <div></div>
  </div>
  <div class="b">
    <div></div>
  </div>
</div>
<style>
  #a {
    position: relative;
    display: block;
    background: yellow;
    width: 500px;
    column-count: 2;
    padding: 10px;
  }
  
  .b {
    background: pink;
    break-inside: avoid;
    height: 50px;
    margin: 10px;
  }
</style>
athi
  • 1,683
  • 15
  • 26