美文网首页
HTML+CSS底部footer两种固定方式

HTML+CSS底部footer两种固定方式

作者: geeooooz | 来源:发表于2018-11-06 15:50 被阅读41次

网页常见的底部栏(footer)目前有两种:

一、永久固定,不管页面的内容有多高,footer一直位于浏览器最底部,适合做移动端底部菜单,这个比较好实现;(向立凯)

二、相对固定,当页面内容高度不沾满浏览器高度,footer显示在浏览器底部,且不会出现滚动条,如果页面内容高度超出浏览器高度,footer则相对与内容的最底部,并且自动出现滚动条;(向立凯)

废话不多说,可以直接复制代码查看效果

一、永久固定

<!DOCTYPE html>
<html>
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   <title></title>
   <meta charset="utf-8" />
   <style>
       body {
           padding-bottom: 50px;
       }

       .footer {
           position: fixed;
           left: 0px;
           bottom: 0px;
           width: 100%;
           height: 50px;
           background-color: #eee;
           z-index: 9999;
       }
   </style>
</head>
<body>
   内容,可以大量复制看效果<br />

   <div class="footer">固定在底部</div>
</body>
</html>

二、相对固定

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <meta charset="utf-8" />
    <style type="text/css">
        * {
            margin: 0px;
            padding: 0px;
        }
 
        html, body {
            height: 100%;
        }
 
        .footer {
            margin-top: -50px;
            height: 50px;
            background-color: #eee;
            z-index: 9999;
        }
 
        .wrap {
            min-height: 100%;
        }
 
        .main {
            padding-bottom: 50px;
        }
    </style>
</head>
<body>
    <div class="wrap">
        <div class="main">
            内容,可以大量复制看效果<br />
 
        </div>
    </div>
    <div class="footer">相对在底部</div>
</body>
</html>

css实现按钮固定在底部

想要把按钮固定在底部,让浏览器滚动时也不受影响。其实代码很简单的啦!
css如下:

<style>
.r{position:fixed; bottom:0;width:360px;left:0px;}
</style>

html如下:

<div>
    <div class="r">
        <input type="submit" value="确认添加"  class="btn btn-primary"/>
    </div>
</div>```

相关文章

  • HTML+CSS底部footer两种固定方式

    网页常见的底部栏(footer)目前有两种: 一、永久固定,不管页面的内容有多高,footer一直位于浏览器最底部...

  • 底部footer固定方式

    相对固定,当页面内容高度不沾满浏览器高度,footer显示在浏览器底部,且不会出现滚动条,如果页面内容高度超出浏览...

  • 利用CSS进行布局和第一天的TODO

    如何让footer固定在底部? 多次在项目中遇到需要将footer固定在底部即使是中间内容并没有充满一屏的高度,如...

  • CSS Footer固定底部处理

    Footer应用场景 自适应内容高度展示在页面最底部 固定于浏览器窗口底部 Footer 自适应内容高度展示在页面...

  • stick footer布局

    在手机端网页中常常会遇到这种布局需求:将footer固定到底部。文章内容不足满屏时 footer在底部,超过满屏时...

  • CSS方案总结

    一、Sticky Footer效果 无论页面内容高度如何变化,footer始终在页面底部的固定位置 二、垂直居中 ...

  • 【css】footer固定在页面底部

    在chrome浏览器中,采用flexbox布局。 在支持flex布局的chrome浏览器中打开,没有问题。但是在I...

  • VUE 元素根据屏幕高度自动调整自身高度

    需求:页面有固定高度的头部header [height:60px],底部footer [height:100px]...

  • 41 紧贴底部的页面

    解决将footer固定在页面底部的问题 在线预览 100vh占据100%可视窗口,利用calc计算,将底部的高度减...

  • H5兼容iphone下巴

    底部盒子加footer的class

网友评论

      本文标题:HTML+CSS底部footer两种固定方式

      本文链接:https://www.haomeiwen.com/subject/wruuxqtx.html