css - 动态网页上的Html5无限滚动

标签 css html

我正在尝试实现一个无限滚动页面,当我添加一个元素时尺寸会发生变化,这里有一张图片来解释我的意思。

enter image description here

有很多 css,所以如果需要我也可以添加它们。

谢谢

最佳答案

你要做的是:

  1. 给你的页眉和页脚一个 fixed position以及定义的高度。

  2. 给出你的主体auto overflow以及等于页眉和页脚高度的填充。

也许这个example会给你方向。您可以创建类似于以下内容的页面布局:

<header id="header-container">
    <div id="site-header">
        Site Header
    </div>
    <div id="main-header">
        Main Header
    </div>
</header>
<footer id="footer-container">
    <div id="main-footer">
        Main Footer
    </div>
    <div id="site-footer">
        Site Footer
    </div>
</footer>
<main id="main-body">
    Main Body
    <ul>
        <li>Item</li>
        <li>Item</li>
        <li>Item</li>
        <li>Item</li>
        <li>Item</li>
        <li>Item</li>
        <li>Item</li>
        <li>Item</li>
        <li>Item</li>
        <li>Item</li>
        <li>Item</li>
        <li>Item</li>
        <li>Item</li>
        <li>Item</li>
        <li>Item</li>
    </ul>
</main>
html, body {
    height: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
}

#header-container {
    position: fixed;
    top: 0;
    width: 100%;
    height: 150px; /* 100px for site header, 50px for main header. */
}

#site-header {
    background-color: #eee;
    height: 100px;
}

#main-header {
    background-color: #cce;
    height: 50px;
}

#footer-container {
    position: fixed;
    bottom: 0;
    width: 100%;
    height: 75px; /* 50px for site footer, 25px for main footer. */
}

#site-footer {
    background-color: #eee;
    height: 50px;
}

#main-footer {
    background-color: #cce;
    height: 25px;
}

#main-body {
    margin: 150px 0 75px; /* 50px on top, 50px on bottom*/
    overflow: auto;
}

关于css - 动态网页上的Html5无限滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27149562/

相关文章:

jquery - CSS隐藏 &lt;input type ="file"> 不隐藏边框

javascript - 无法让这个 CSS/jQuery 下划线动画工作,我做错了什么?

javascript - 设置 jQuery UI Spinner 以调整宽度以使文本适合

javascript - 自定义元素 vs 网络组件自定义元素

php - 是否可以将 font Awesome 图标制作为占位符中的按钮?

HTML 中的 PHP if/else 结构

javascript - 在旧浏览器中显示 Flexbox

html - 如何仅使用一行 css 将第 2 个和第 3 个元素作为第 n 个子元素的目标?

javascript - 从 extjs 按钮中删除轮廓

php - 在表格单元格中对齐