Responsive Design: Why does height zero & padding-bottom work for making a div responsively sized?

前端 未结 1 1447
Happy的楠姐
Happy的楠姐 2021-02-09 05:34

After looking through Zurb Foundation\'s code, I noticed they were using a CSS approach like this to allow a responsive square div:

.div{
    position:relative;
         


        
相关标签:
1条回答
  • 2021-02-09 06:34

    The second element is positioned absolutely relative to is container. Which is positioned relative.

    In CSS, percentage based padding is relative to the width of the element. That is what creates the square effect.

    And is also why if you add the same size padding to all sides, all sides have the same percentage of padding. It is relative to one measurement (width) and NOT both width and height. that would cause the padding to be skewed if the the element was not square.

    0 讨论(0)
提交回复
热议问题