Search code examples
cssfontsgoogle-material-icons

Why doesn't overflow: hidden work with material icons?


In the sample below, why doesn't overflow: hidden; work on the tile object?

#tileContainer {
  background-color: gray;
  padding: 10px;
}
.tile {
  display: inline-block;
  padding: 10px;
  margin: 10px;
  width: 120px;
  height: 120px;
  background-color: white;
  overflow: hidden;
}

.tile i {
  opacity: .25;
  position: absolute;
  font-size: 150px;
  left: -10px;
  top: 25px;
}
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<div id="tileContainer">
  <div class="tile">
    <i class="material-icons">account_balance</i>
    <div id="tileContent">
      Stuff goes here.
    </div>
  </div>
  <div class="tile">
    <div id="tileContent">
      Stuff goes here.
    </div>
  </div>
</div>

The desired result is something more like this:

enter image description here


Solution

  • It works when you add position: relative to .tile. I guess it is because position: absolute pulls the element out of the flow of the tile.