Maintain div aspect ratio according to height

前端 未结 5 2035
日久生厌
日久生厌 2020-11-28 12:05

I need to maintain the width of an element as a percentage of its height. So as the height changes, the width is updated.

The oppo

5条回答
  •  自闭症患者
    2020-11-28 12:22

    The CSS trick you wrote, works pretty well to keep ratio width / height on an element. It is based on the padding property that, when its value is in percent, is proportional to parent width, even for padding-top and padding-bottom.

    There is no CSS property that could set an horizontal sizing proportionally to the parent height. So I think there is no clean CSS solution.

提交回复
热议问题