840 B
840 B
title, type, tags, cover, dateModified
| title | type | tags | cover | dateModified | |
|---|---|---|---|---|---|
| Constant width to height ratio | snippet |
|
clutter | 2020-12-30T15:37:37+02:00 |
Ensures that an element with variable width will retain a proportionate height value.
- Apply
padding-topon the::beforepseudo-element, making theheightof the element equal to a percentage of itswidth. - The proportion of
heighttowidthcan be altered as necessary. For example apadding-topof100%will create a responsive square (1:1 ratio).
<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;
}