当前位置:首页 > CSS

css制作固定模板

2026-02-12 15:31:00CSS

使用CSS创建固定模板

固定模板通常指具有固定头部、底部或侧边栏的布局结构。以下是几种常见实现方法:

固定头部和底部

<!DOCTYPE html>
<html>
<head>
    <style>
        body {
            margin: 0;
            padding: 0;
            font-family: Arial;
        }
        .header {
            position: fixed;
            top: 0;
            width: 100%;
            height: 60px;
            background: #333;
            color: white;
            text-align: center;
            line-height: 60px;
        }
        .content {
            margin-top: 60px;
            margin-bottom: 60px;
            padding: 20px;
            height: calc(100vh - 140px);
            overflow-y: auto;
        }
        .footer {
            position: fixed;
            bottom: 0;
            width: 100%;
            height: 60px;
            background: #333;
            color: white;
            text-align: center;
            line-height: 60px;
        }
    </style>
</head>
<body>
    <div class="header">头部区域</div>
    <div class="content">主要内容区域</div>
    <div class="footer">底部区域</div>
</body>
</html>

固定侧边栏布局

<!DOCTYPE html>
<html>
<head>
    <style>
        body {
            margin: 0;
            padding: 0;
            font-family: Arial;
        }
        .sidebar {
            position: fixed;
            left: 0;
            top: 0;
            width: 200px;
            height: 100vh;
            background: #333;
            color: white;
        }
        .main-content {
            margin-left: 200px;
            padding: 20px;
        }
    </style>
</head>
<body>
    <div class="sidebar">侧边栏</div>
    <div class="main-content">主要内容区域</div>
</body>
</html>

使用CSS Grid创建固定模板

<!DOCTYPE html>
<html>
<head>
    <style>
        body {
            margin: 0;
            padding: 0;
            font-family: Arial;
            display: grid;
            grid-template-rows: auto 1fr auto;
            grid-template-columns: 100%;
            min-height: 100vh;
        }
        header {
            grid-row: 1;
            background: #333;
            color: white;
            padding: 20px;
            text-align: center;
        }
        main {
            grid-row: 2;
            padding: 20px;
        }
        footer {
            grid-row: 3;
            background: #333;
            color: white;
            padding: 20px;
            text-align: center;
        }
    </style>
</head>
<body>
    <header>头部区域</header>
    <main>主要内容区域</main>
    <footer>底部区域</footer>
</body>
</html>

响应式固定模板

<!DOCTYPE html>
<html>
<head>
    <style>
        body {
            margin: 0;
            padding: 0;
            font-family: Arial;
        }
        .container {
            display: flex;
            min-height: 100vh;
        }
        .sidebar {
            width: 250px;
            background: #333;
            color: white;
            position: fixed;
            height: 100vh;
        }
        .content {
            margin-left: 250px;
            padding: 20px;
            flex: 1;
        }
        @media (max-width: 768px) {
            .sidebar {
                width: 100%;
                height: auto;
                position: relative;
            }
            .content {
                margin-left: 0;
            }
            .container {
                flex-direction: column;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="sidebar">侧边栏</div>
        <div class="content">主要内容区域</div>
    </div>
</body>
</html>

关键CSS属性说明

  • position: fixed - 使元素固定在视口中
  • top/bottom/left/right - 控制固定元素的位置
  • calc() - 用于动态计算尺寸
  • vh - 视口高度单位
  • grid - CSS网格布局
  • flex - 弹性盒布局
  • @media - 响应式设计媒体查询

这些方法可以根据具体需求组合使用,创建出各种固定布局模板。

css制作固定模板

标签: 模板css
分享给朋友:

相关文章

网页制作 css

网页制作 css

CSS 基础语法 CSS(层叠样式表)用于控制网页的样式和布局。基本语法由选择器和声明块组成: 选择器 { 属性: 值; } 例如设置段落文字颜色为红色: p { color: red…

css 制作表格

css 制作表格

基础表格结构 使用HTML的<table>标签创建表格框架,搭配<tr>(行)、<th>(表头)和<td>(单元格)标签。例如: <table…

css div 制作导航菜单

css div 制作导航菜单

基本导航菜单结构 使用HTML创建一个简单的导航菜单结构,通常使用<ul>和li>列表实现。每个菜单项用<a>标签包裹以实现链接功能。 <div class="…

css 字体库制作

css 字体库制作

创建 CSS 字体库的步骤 准备字体文件 确保拥有字体文件的合法使用权,常见的格式包括 .woff、.woff2、.ttf 或 .otf。推荐使用 woff2 格式,因其压缩率更高且现代浏览器广泛支持…

css制作简历

css制作简历

使用CSS制作简历的步骤 设计简历结构 使用HTML创建简历的基本结构,包括个人信息、教育背景、工作经历、技能等部分。确保每个部分都有清晰的标题和内容区域。 基础样式设置 通过CSS设置全局样式,…

dw制作css

dw制作css

使用DW(Dreamweaver)制作CSS的步骤 在Adobe Dreamweaver中创建和编辑CSS文件可以通过可视化界面或直接编写代码完成。以下是具体操作方法: 新建CSS文件 打开Drea…