FrenkyB FrenkyB - 3 months ago 14
HTML Question

Non-equal space between divs

I have several divs with margin-bottom: 5px. What it's not logic to me is, that spacing between divs is not equal. If I insert some text into div, space decreases. Without text, space increases.

Here is example from code pen

It looks like this:

enter image description here

All divs have position: relative and margin-bottom: 5px:

.divNote{
position: relative;
display: inline-block;
left: 20%;
width: 60%;
min-height: 60px;
margin-bottom: 5px;
background-color: #FAC28A;
font-family: verdana, sans-serif;
font-size: 15px;
color: #003399;
padding-left: 5px;
padding-top: 1px;
padding-bottom: 20px;
box-shadow: 3px 3px 3px gray;
box-sizing: border-box;
}

Answer

Set float:left to .divNote this will work.

@border: 1px;

.divMain{
  position: absolute;
  height: 100vh;
  width: 100vw;  
}

.divNote{
  position: relative;
  display: inline-block;  
  left: 20%;
  width: 60%;
  min-height: 60px;  
  margin-bottom: 5px;
  background-color: #FAC28A;
  font-family: verdana, sans-serif;
  font-size: 15px;
  color: #003399;
  padding-left: 5px;
  padding-top: 1px;
  padding-bottom: 20px;
  box-shadow: 3px 3px 3px gray;    
  box-sizing: border-box;
  float:left;
}

.divNoteDatum{
  position: absolute;
  display: inline-block;   
  font-weight: bold;      
  bottom: 0;
  right: 5px;
  color: #003399;
}

.divUpper{
  position: relative;
  height: 20%;
}
<div id="divMain" class="divMain">

  <div class="divUpper"></div>

  <div id="divNote" class="divNote">
    test<br/>test<br/>test
    <div id="divNoteDatum" class="divNoteDatum">12.08.2016 11:08</div>
  </div>
  
    <div id="divNote" class="divNote">
    
    <div id="divNoteDatum" class="divNoteDatum">12.08.2016 11:08</div>
  </div>
  
    <div id="divNote" class="divNote">
    test<br/>test<br/>test
    <div id="divNoteDatum" class="divNoteDatum">12.08.2016 11:08</div>
  </div>
  
    <div id="divNote" class="divNote">
    test<br/>test<br/>test
    <div id="divNoteDatum" class="divNoteDatum">12.08.2016 11:08</div>
  </div>
  
    <div id="divNote" class="divNote">
    
    <div id="divNoteDatum" class="divNoteDatum">12.08.2016 11:08</div>
  </div>
  
  
    <div id="divNote" class="divNote">
    
    <div id="divNoteDatum" class="divNoteDatum">12.08.2016 11:08</div>
  </div>
  
    <div id="divNote" class="divNote">
    
    <div id="divNoteDatum" class="divNoteDatum">12.08.2016 11:08</div>
  </div>


</div>
<!-- divMain -->