首页 > 其他分享 >CSS Sticky Footer实现

CSS Sticky Footer实现

时间:2022-11-12 10:44:27浏览次数:32  
标签:Footer some 100px Sticky content background height CSS 页面

Sticky Footer(粘黏页脚)指的是在页面布局时,当页面的内容不足或等于一屏时,让页脚始终保持在页面的底部,如同粘在底部一样;当页面的内容超过一屏时,即页面发生滚动时,页脚跟随文档,仍然处在页面文档的底部。 简而言之,就是“页脚置底”。

image

CSS2 实现

效果图

image

实现代码

<!DOCTYPE html>
<html lang="en">
<head>
  <style>
    * {
      margin: 0;
      padding: 0;
      font-size: 100px;
    }
    .wrapper {
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background-color: #ccc;
      overflow-y: scroll;
    }
    .content {
      width: 100%;
      min-height: 100%;
    }
    .content-main {
      padding-bottom: 100px;
    }
    .footer {
      height: 100px;
      background-color: orange;
      margin-top: -100px;
    }
  </style>
</head>
<body>
  <!-- 全局容器 -->
  <div class="wrapper">
    <!-- 内容层 -->
    <div class="content">
      <div class="content-main">
        <p>this is some content</p>
        <p>this is some content</p>
        <p>this is some content</p>
        <p>this is some content</p>
        <p>this is some content</p>
        <p>this is some content</p>
        <!-- <p>this is some content</p>
        <p>this is some content</p>
        <p>this is some content</p>
        <p>this is some content</p>
        <p>this is some content</p>
        <p>this is some content</p>
        <p>this is some content</p> -->
      </div>
    </div>
    <!-- Sticky Footer -->
    <div class="footer"></div>
  </div>
</body>
</html>

flex 实现

效果图

image

实现代码

<!DOCTYPE html>
<html lang="en">
<head>
  <style>
    * {
      margin: 0;
      padding: 0;
      font-size: 100px;
    }
    .container {
      min-height: 100vh;
      display: flex;
      flex-direction: column;
    }
    .content {
      flex: 1;
      background-color: #ccc;
    }
    .footer {
      height: 100px;
      background-color: orange;
    }
  </style>
</head>
<body>
  <!-- 全局容器 -->
  <div class="container">
    <!-- 内容层 -->
    <div class="content">
      <p>this is some content</p>
      <p>this is some content</p>
      <p>this is some content</p>
      <p>this is some content</p>
      <p>this is some content</p>
      <p>this is some content</p>
      <!-- <p>this is some content</p>
      <p>this is some content</p>
      <p>this is some content</p>
      <p>this is some content</p>
      <p>this is some content</p>
      <p>this is some content</p> -->
    </div>
    <!-- Sticky Footer -->
    <div class="footer"></div>
  </div>
</body>
</html>

标签:Footer,some,100px,Sticky,content,background,height,CSS,页面
From: https://www.cnblogs.com/huangtq/p/16882860.html

相关文章

  • CSS的预处理器---[Less]
    CSS的预处理器---[Less]Less中文网址:http://lesscss.cn/常见的CSS预处理器:Sass、Less、Stylus1.Less使用我们首先新建一个后缀名为less的文件,在这个less文件里面书写......
  • 【面试】909- 59 道 CSS 面试题(附答案)
    CSS部分的面试题主要考察应试者对CSS基础概念模型的理解,例如文档流、盒模型、浮动、定位、选择器权重、样式继承等。很多应试者认为CSS很简单,没多少内容,面试就是面试JavaSc......
  • 【CSS】11 个 Sass 中常用的颜色函数,你需要知道一下
    今天我们来看一下Sass中的颜色函数,颜色函数可以分为三部分,分别是颜色设置、颜色获取以及颜色操作。Sass中的颜色函数有很多,下面我们来看一下这11个Sass中常用的颜色函......
  • CSS样式
    /*粘性布局,使导航固定*/position:sticky;top:0rpx;/*实现垂直居中的方法:(1)绝对定位法:这个方法就是利用绝对定位,使它的top、left、right、bott......
  • asp.net分页控件CSS
    .aspx代码如下:<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Sample3_DataPager.aspx.cs"Inherits="Sample_03_DataPager"%><!DOCTYPEhtmlPUBLIC"-//W3C/......
  • CSS背景样式使用
    语法:background-color:transparent|color取值:transparent:默认值。背景色透明color:指定颜色。请参阅颜色单位​和附录:颜色表说明:设置或检......
  • css中z-index层级
    1.z-index简介(1)概念z-index属性指定了元素与元素之间的z轴上的顺序,而z轴决定元素之间发生覆盖的层叠关系。(2)属性值1.默认auto为什么元素添加定位属性(不包括sta......
  • CSS通过Flex实现上标
    效果图Code<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metahttp-equiv="X-UA-Compatible"content="IE=edge"><metaname="view......
  • CSS导航栏最后一个元素居右(.nav-site .nav-right{margin-left: auto;}
    效果如图Code<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metahttp-equiv="X-UA-Compatible"content="IE=edge"><metaname="vi......
  • 学习笔记 之 简单了解有关 CSS 那点事儿
    LZ-Says:调整心态,多读书,丰富内心,提升个人文化底蕴。前言前几天,初步了解了下HTML相关的知识点,在学习回顾时,还好,大部分都在,只是新增了一些其他内容,例如自适应等等。上手......