CSS底部固定是指将网页中的一个元素(通常是页脚)固定在浏览器窗口的底部,无论页面内容的多少,该元素都会保持在视口的底部。
position: fixed; 和 bottom: 0; 将元素固定在底部。display: flex; 和 flex-direction: column;,然后将子元素(页脚)设置为 margin-top: auto;。<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>底部固定示例</title>
<style>
.footer {
position: fixed;
bottom: 0;
width: 100%;
background-color: #333;
color: white;
text-align: center;
padding: 10px 0;
}
</style>
</head>
<body>
<div class="content">
<!-- 页面内容 -->
</div>
<div class="footer">
版权所有 © 2023
</div>
</body>
</html><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>底部固定示例</title>
<style>
body {
display: flex;
flex-direction: column;
min-height: 100vh;
margin: 0;
}
.content {
flex: 1;
}
.footer {
background-color: #333;
color: white;
text-align: center;
padding: 10px 0;
}
</style>
</head>
<body>
<div class="content">
<!-- 页面内容 -->
</div>
<div class="footer">
版权所有 © 2023
</div>
</body>
</html>@media)。body 的 margin 设置为0,并确保 html 和 body 的高度为100%。通过以上方法,你可以实现一个固定在页面底部的元素,提升用户体验和设计一致性。
没有搜到相关的文章