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.html
has no parent... also applying flexbox tohtml
is useless as it only has 1 child element that is visible:body
.
Actually:
- I put
100%
ofhtml
height in order to have it fit the screen height. - I apply flexbox to
html
in order to be able to useflex-glow: 1
on its child, and have this child filling its parent.
Is there any better to solution than mine?