What is the difference between applying css rules to html compared to body?

前端 未结 5 912
梦如初夏
梦如初夏 2020-12-01 16:06

I don\'t see the difference between:

html {
    background: #f1f1f1;
}

and

body {
    background: #f1f1f1;
}
5条回答
  •  一个人的身影
    2020-12-01 16:29

    html is the parent of body. One way to see the difference is to do:

    html {
        overflow: scroll;
    }
    
    
    body {
        overflow: scroll;
    }
    

    You will see that there are two nested sets of scrollbars, one belonging to html and the one inside that belonging to body.

提交回复
热议问题