-2

Below is the given html code,

<div class="row">
  <div class="column">
    Some text
  </div>
  <div class="column blue">
    Some other text
  </div>
</div>

First case - Below is the css code applied, without setting margin,

.row {
   background: red; 
}

.column {
  #margin: 10px;
  background: green;
}

.blue {
  background: blue;
}

and the output is:

enter image description here

Second case - Below is the css code, after setting margin,

.row {
   background: red; 
}

.column {
  margin: 10px;
  background: green;
}

.blue {
  background: blue;
}

with the output,

enter image description here

Third case - Below is the css code, with overflow set as hidden

.row {
  background: red; 
  overflow: hidden;
}

.column {
  margin: 10px;
  background: green;
}

.blue {
  background: blue;
}

with the output,

enter image description here

1)

In above second case, Why does the container having 2 div elements does not expand on top margin?

2)

In above third case, Why does the container having 2 div elements expand on top margin?

overexchange
  • 15,768
  • 30
  • 152
  • 347
  • 1
    Did you not read the post [I linked you to in chat](http://chat.stackoverflow.com/transcript/message/25785311#25785311) (which your question has just been marked a duplicate of)? If you did, what did you not understand from my answer? – BoltClock Sep 18 '15 at 12:29

1 Answers1

0

By placing an overflow:hidden on the containing element you are changing it's Block Formatting Context. Only a few styles do this.

I usually use this method to self clear modules.

Adam Hughes
  • 2,197
  • 20
  • 31