+ 1

why this happen in css?

https://code.sololearn.com/Wi60wsW3C1Q8/?ref=app why height of body is 0?

6th Apr 2021, 9:23 PM
Mehran
Mehran - avatar
5 Réponses
+ 1
Because you don't put anything related to height at body block style in css file
6th Apr 2021, 9:37 PM
Raven
Raven - avatar
+ 1
Raven i understand it. but when we set background-color, The whole of page (Even margins) set to green why?
6th Apr 2021, 9:39 PM
Mehran
Mehran - avatar
+ 1
Mehran Raeesi I'm not pretty sure, I left css from a while, You can't say body is an element like div, You can put div inside the body and give it width and height
6th Apr 2021, 9:58 PM
Raven
Raven - avatar
+ 1
Mehran Raeesi the colour shows but there is no set height because you don't have any content (child html elements/DOM nodes) within the body. I know it seems a bit weird but by default, the height of the body is set to auto. That means if you don't set a height, it'll take up the height of the content. Btw, you'll probably want to set a min-height as opposed to height so that it can grow. If in your CSS you want to use percentages and min-height but you don't have any content, you'll have to set the height of the parent of the body as well, which is the html. html { height: 100%; } body { min-height: 10%; }
6th Apr 2021, 10:27 PM
CamelBeatsSnake
CamelBeatsSnake - avatar
+ 1
Because you don't use related to height...[][][]
7th Apr 2021, 6:11 AM
❴Amit ❵
❴Amit ❵ - avatar