html - 固定页眉和固定菜单栏

标签 html css

我一直在修补这个问题太久了,所以我把问题放在这里。我想在网页顶部有一个菜单栏。我的方法的问题是内容页面滚动到菜单栏“后面”,这会导致 DataTable/FixedHeader 出现问题。 .它不会在菜单处停止表格的标题,而是滚动到菜单中并锁定在屏幕顶部。 enter image description here .

CSS 看起来像这样

#header {
    width:100%;
    height:50px;
    position: fixed;
    top:0;
    background-color:rgba(255,0,0,0.5);
}


#content {
    background-color:rgba(0,0,255,0.5);
    position: static;
    margin-top: 50px;
}

我能做些什么来阻止表格一直向上滚动并且标题停止在菜单下方吗?

最佳答案

我想您可能会在 DataTable/FixedHeader 的文档中找到答案。如您所见,您可以 specify the following :

offsetTop Specify an offset from the top of the window where the fixed header where be locked to when scrolling. This is useful for working with fixed elements at the top of the page - for example the Twitter Bootstrap fixed menu.

$(document).ready( function () {
    var oTable = $('#example').dataTable();
    new FixedHeader( table, {
        "offsetTop": 40
    } );
} );

offsetTop 更改为菜单栏的高度 (50),一切就绪!

此外,您还可以向 #header 添加一个大的 z-index 以确保它位于其他元素的“顶部”。

#header {
    z-index: 9999;
    /* And your other properties here */
}

关于html - 固定页眉和固定菜单栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14424972/

相关文章:

javascript - 带 HTML 标签的换行符

javascript - 如何只选择具有特定 CSS 类的节点? D3/JS

html - 背面可见性问题 :hidden;

c# - 如何使用 HTMLTextWriter 加载 CSS 文件

html - 将焦点应用于标记父级

javascript - 折叠 div 的 Accordion 菜单 CSS3、HTML5 问题

javascript - 给定代码的 Stripe 元素不显示自定义付款表单

html - 使用浏览器调整图像大小

javascript - jQuery/JavaScript : tidy html

html - div 中的垂直对齐下拉列表