设置footer位于底部
要将footer设置为位于底部,可以使用CSS来实现。以下是一种常见的方法:
HTML:
<body>
<header>...</header>
<main>...</main>
<footer>...</footer>
</body>
CSS:
body {
display: flex;
flex-direction: column;
min-height: 100vh;
}
main {
flex: 1;
}
footer {
margin-top: auto;
}
通过将body元素的display属性设置为flex,并将flex-direction设置为column,可以将页面内容垂直排列。将main元素的flex属性设置为1可以使其占据剩余的空间。最后,通过将footer元素的margin-top属性设置为auto,可以将其推到页面的底部。
原文地址: https://www.cveoy.top/t/topic/h6ua 著作权归作者所有。请勿转载和采集!