0

I'm failing to understand why overflow: hidden solve my floating problem: I don't want the words to be inside the picture in the left.

I also read Understanding CSS Layout And The Block Formatting Context.

The example is taken from https://internetingishard.com/html-and-css/floats/ but lacks the explanation of why.

.column {
  overflow: hidden;
  float: left;
  width: 31%;
  margin: 20px 1.15%;
  height: 160px;
  background-color: #B2D6FF;
  /* Medium blue */
}

.avatar {
  float: left;
  width: 60px;
  height: 60px;
  margin: 25px;
  border-radius: 40px;
  background-color: #D6E9FE;
}

.username {
  margin-top: 30px;
}

.comment {
  margin: 10px;
  overflow: hidden;
  /* This is important */
}
<div class='column'>
  <div class='avatar'></div>
  <h3 class='username'>Bob Smith</h3>
  <p class='comment'>Aptent vel egestas vestibulum aliquam ullamcorper volutpat</p>
</div>
Stav Alfi
  • 13,139
  • 23
  • 99
  • 171

1 Answers1

-1

When you float something, it gets removed from the document "flow", and as such containers will ignore that element since it's removed from said flow. When you add the overflow: hidden property you're telling that container to re-include the floated element and incorporate it into its sizing.

wtitus
  • 119
  • 4
  • Thanks but I think you didn't answer my question: ___Why___ `overflow: hidden` solve ___this specific___ floating problem: I don't want the words to be inside the picture in the left. – Stav Alfi Sep 29 '18 at 16:32