Вот проблема:
- Когда я увеличиваю ширина родительского контейнера, дочерний элемент корректируется правильно, сохраняя соотношение сторон.
- Однако, когда я значительно увеличиваю высоту родительского контейнера, высота дочернего элемента выходит за пределы ограничений соотношения сторон, нарушение макета.
Код: Выделить всё
#parent {
height: 90px;
width: 160px;
background-color: red;
display: flex;
justify-content: center;
/* tried to add: align-items: center; - it makes the child disappear. */
}
#child {
height: auto; /* tried also: max-height: 100%; */
max-width: 100%;
aspect-ratio: 16 / 9;
background-color: yellow;
object-fit: contain;
}
increase height
increase width
var height = 90;
var width = 160;
function increaseHeight() {
height += 100;
document.getElementById('parent').style.height = height + 'px';
}
function increaseWidth() {
width += 100;
document.getElementById('parent').style.width = width + 'px';
}
Подробнее здесь: https://stackoverflow.com/questions/792 ... eeds-limit
Мобильная версия