I often need that html and body elements have the size of the screen. Typically, in the case when I want to have a svg element fit the whole screen.
To achieve that, I saw that it was possible to use CSS code as follow.
html,body{margin:0;padding:0;height:100%;}
The code that I personnaly use is the following one.
html {
height: 100%;
display: flex;
}
body {
flex-grow: 1;
display: flex;
flex-direction: column;
}
Both seem to work well, but I recently had the following remark.
html { height: 100%; display: flex; }is a useless declaration. html height will always be calculated to fit content. Also100%means 100% of the parent.htmlhas no parent... also applying flexbox tohtmlis useless as it only has 1 child element that is visible:body.
Actually:
- I put
100%ofhtmlheight in order to have it fit the screen height. - I apply flexbox to
htmlin order to be able to useflex-glow: 1on its child, and have this child filling its parent.
Is there any better to solution than mine?