Why is is top:50% in css not working?

Using Position – Static height needed

i{
  -webkit-transform: translate(-50%,-50%);
  transform: translate(-50%,-50%);
  position: absolute;
  top: 50%;
  left: 50%;
}
<i>center</i>

Edit: Using Flex (2021-10-19)

i {
  display: flex;
  align-items: center; /* vertical centering if flex-direction: row */
  justify-content: center; /* horizontal centering if flex-direction: row */

  /* extra styles */
  background-color: limeGreen;
  min-height: 160px;
}
<i>center</i>
enter code here

Leave a Comment