Skip to content

Home

Constant width to height ratio

Ensures that an element with variable width will retain a proportionate height value.

<div class="constant-width-to-height-ratio"></div>
.constant-width-to-height-ratio {
  background: #9C27B0;
  width: 50%;
}

.constant-width-to-height-ratio::before {
  content: '';
  padding-top: 100%;
  float: left;
}

.constant-width-to-height-ratio::after {
  content: '';
  display: block;
  clear: both;
}

More like this

Start typing a keyphrase to see matching snippets.