100% height not working as expected

前端 未结 2 1207
迷失自我
迷失自我 2021-01-23 09:42

In my html, there\'re a couple of divs. but none of these is showing the background image. and, of course that\'s because 100% property is not working. why is this happening?

相关标签:
2条回答
  • 2021-01-23 10:31

    Your div.section needs to be relative to another div in order for the height: 100% to work.

    0 讨论(0)
  • 2021-01-23 10:39

    100% of what?

    You need to define the parent's dimensions in order for this to work, otherwise 100% of 0, is also 0%.

    In this example, since the parent element is body, you would have to set both the height of that and html to 100%. Doing this, will allow for the child element to have a height of 100%.

    body, html {
        height: 100%;
    }
    

    jsFiddle example - it works.

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