无需自定义CSS,使用 Bootstrap 即可实现可视窗口高度自适应、Sticky Bottom 效果的网页底部信息条。
    不多说,例子上来,将以下HTML代码复制 / 粘贴到新建的空白 test.html 文件中,保存后直接用浏览器打开即可看到效果。

    1. <!DOCTYPE html>
    2. <html class="h-100">
    3. <head>
    4. <meta charset="utf-8">
    5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
    6. <meta name="viewport" content="width=device-width, initial-scale=1">
    7. <title>Sticky Bottom Test</title>
    8. <meta name="description" content="Sticky Bottom Test">
    9. <link rel="shortcut icon" href='favicon.ico' type="image/x-icon">
    10. <!-- Front End Framework: JQuery / Bootstrap -->
    11. <link href="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet">
    12. </head>
    13. <body class="d-flex flex-column h-100">
    14. <main role="main" class="flex-shrink-0">
    15. <div class="container mt-5">
    16. Write your body content here...
    17. <p>
    18. Hello, Github, Baidu, Google, and you, and you......
    19. </p>
    20. </div>
    21. </main>
    22. <footer class="bg-dark mt-auto py-3">
    23. <div class="container text-center text-secondary">
    24. Sticky bottom bar. Copyrights logo and information.
    25. </div>
    26. </footer>
    27. <!-- Scripts begin -->
    28. <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
    29. <script src="https://cdn.bootcss.com/popper.js/1.15.0/esm/popper.min.js"></script>
    30. <script src="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
    31. <script>
    32. $(window).ready(function() {
    33. // Customize scripts here...
    34. });
    35. </script>
    36. <!-- Scripts end -->
    37. </body>
    38. </html>

    以下把最主要的样式框架代码单独列出,即可大致看出 Bootstrap Sticky Bottom 样式的应用模式:

    1. <html class="h-100">
    2. ...
    3. <body class="d-flex flex-column h-100">
    4. <main role="main" class="flex-shrink-0">
    5. ...
    6. </main>
    7. <footer class="bg-dark mt-auto py-3">
    8. ...
    9. </footer>
    10. ...
    11. </body>
    12. </html>