0

My html has 2 sections, margin is zero but it still showing

.box1 {
  width: 300px;
  height: 450px;
  background-color: green;
  border: 0px;
  display: inline-block;
  margin: 0;
  padding: 0px;
}

.box2 {
  width: 150px;
  height: 300px;
  background-color: purple;
  border: 0px;
  display: inline-block;
  margin: 0;
  padding: 0px;
}
<body>
  <div class="box2"></div>
  <div class="box1"></div>
</body>

this is result

Carl Binalla
  • 5,393
  • 5
  • 27
  • 46
Mladen Milosavljevic
  • 1,720
  • 1
  • 12
  • 23

1 Answers1

3

It is not the margin. It is the new lines converted to "spaces" when displaying it.It is because of the display:inline-block of the div . You can either remove the space or remove that with comments <!-- --> between the divs

.box1 { width: 300px;
height: 450px;
background-color: green;
border: 0px;
display: inline-block;
margin: 0;
padding: 0px; }

.box2 { width: 150px;
height: 300px;
background-color: purple;
border: 0px; 
display: inline-block;
margin: 0;
padding: 0px;}
<div class="box2"></div><!--

   --><div class="box1"></div>

 
XYZ
  • 4,450
  • 2
  • 15
  • 31