Vue导航Footer组件如何实现动态高度自适应?
我在开发导航页脚组件时遇到问题,Footer总被内容遮挡。当页面内容较少时页脚能贴在底部,但内容多时反而被覆盖。我尝试用position: fixed定位,但会导致滚动时内容穿透,换用绝对定位又需要手动计算父容器高度,感觉很麻烦。
<template>
<div class="container">
<main>{{ content }}</main>
<footer class="footer">© 2024 MySite</footer>
</div>
</template>
<style>
.container { position: relative; }
.footer {
position: absolute;
width: 100%;
bottom: 0;
}
</style>
这样写在内容超过一屏时页脚会覆盖底部内容,有没有更优雅的布局方案?或者Tailwind的类名组合可以解决这个问题?
景岩
Lv1
用 flex 布局最简单,直接这样:
点赞
10
2026-02-04 11:11