Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

html网页最底部怎么做

作者:空白篇pia~   发布日期:2026-02-17   浏览:74

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>网页最底部示例</title>
    <style>
        /* 设置body和html的高度为100%,确保页面内容不满屏时footer也能在底部 */
        html, body {
            height: 100%;
            margin: 0;
        }

        /* 主体内容区域 */
        .content {
            min-height: 100%;
            margin-bottom: -50px; /* 负的footer高度 */
            padding-bottom: 50px; /* footer高度 */
        }

        /* 底部区域 */
        footer {
            height: 50px;
            background-color: #f8f9fa;
            text-align: center;
            line-height: 50px; /* 使文本垂直居中 */
        }
    </style>
</head>
<body>
    <div class="content">
        <!-- 页面主要内容 -->
        <h1>欢迎来到我的网页</h1>
        <p>这里是网页的主要内容。</p>
    </div>
    <footer>
        这是网页的最底部
    </footer>
</body>
</html>

解释说明:

  1. HTML结构

    • htmlbody 标签设置了 height: 100%,确保整个页面的高度至少为视口高度。
    • .content 类用于包裹页面的主要内容,并通过 min-height: 100% 确保其最小高度为视口高度。同时,使用负的 margin-bottom 和正的 padding-bottom 来抵消 footer 的高度,从而确保 footer 在页面底部。
  2. CSS样式

    • footer 标签设置了固定的高度(例如 50px),并使用背景颜色、文本对齐和行高等样式来美化底部区域。
    • 当页面内容较少时,footer 会始终位于页面底部;当内容较多时,footer 会自然地跟随内容出现在页面底部。

这种方式可以确保 footer 在页面内容不足时依然位于浏览器窗口的底部,而在内容超出时则正常跟随内容显示。

上一篇:漂亮html5树形结构

下一篇:html下拉列表代码怎么写

大家都在看

静态html源码

404 html

ios打开html

nginx访问不到html

html 符号

colspan在html中是什么意思

怎么将网页另存为html

xml转html

html时间代码

html localstorage

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站