Sometimes, you may want to conditionally set the height of a div, such as when the entire content is less than the height of the screen. Setting all parent elements to 100% will cut off content when it is longer than the screen size.
So, the way to get around this is to set the min-height:
Continue to let the parent elements automatically adjust their height
Then in your main div, subtract the pixel sizes of the header and footer div from 100vh (viewport units). In css, something like:
min-height: calc(100vh - 246px);
100vh is full length of the screen, minus the surrounding divs.
By setting min-height and not height, content longer than screen will continue to flow, instead of getting cut off.
本文介绍如何在CSS中使用min-height属性避免内容被截断,通过设置`min-height: calc(100vh - (header + footer)高度)`,确保长内容流畅显示,不会因屏幕大小而受限。
306

被折叠的 条评论
为什么被折叠?



