html - 当用户调整窗口大小时,表格会缩小。页脚插入它的内容而不重叠它

标签 html css

Picture of table

我有一个页脚有表格和容器的页面。我想让它们响应浏览器窗口的大小,并且我不希望在调整大小时页脚与表格重叠。我想让 table 分别缩小。 这是我到目前为止的代码示例。我需要改进它:

<main>
<div class="container">
<table class="table table-striped">
      ...content of the table here...
 </table>
</div>
</main>
<footer>
<div class="container">This is footer</div>
</footer>

<style>
body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
 }
main {
   flex: 1 0 auto;
}
.container {
    width: 80%;
   margin: 0 auto;
   padding: 1rem;
  }
  footer {
    flex: 0 0 auto;
    background-color: #eee;
    border-top: 1px solid #ddd;
    background:orange;
    }
</style>

最佳答案

如果我们假设您的页脚高度为 100 像素,您可以将表格包裹在一个 div 中,并为您的 div 设置最大高度:

#divTableWrapper{
  max-height:calc(100vh - 100px);
  overflow-y: auto;
}   

或者您可以将页脚设置为始终位于正文底部的固定元素:

footer{
  position: fixed;
  width: 100vw;
  bottom: 0;
  }

关于html - 当用户调整窗口大小时,表格会缩小。页脚插入它的内容而不重叠它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41938563/

相关文章:

css - Apexcharts.js 条形图 CSS 问题

php - 引用 JOINed MySQL 数据,如 JSON 表

html - 如何使用 css 修改链接文本(html 链接)属性

jquery - 将 div 滑动到 div 的顶部

jquery - 如何在 div 元素中垂直和水平居中文本

html - 如何设置元素的顺序 HTML CSS

javascript - 为什么我的一些 JQuery 立即加载,而其他部分需要十多分钟才能加载到页面上(或从未加载)?

html - 同一行的label和radio不跨越td宽度

javascript - 两个 CSS 类具有不同的边框颜色值,并且只有一个有效

javascript - 位置 :fixed difference in IE Vs Firefox