How is padding-top as a percentage related to the parent's width?

后端 未结 5 2112
[愿得一人]
[愿得一人] 2020-11-29 05:35

Here is an example:

http://jsfiddle.net/QZAd8/1/

Notice how all of the red divs are the same height and have padding-top:100%;, yet

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-29 05:57

    If you came here looking for an alternative like I did, you can set padding-top as a percentage of vertical height using a CSS calculation:

    padding-top: calc(.25 * 100vh);
    

提交回复
热议问题