Bootstrap 粘页脚,你必须得学会的简单技能(2)

简介: Bootstrap 粘页脚,你必须得学会的简单技能

③、css分析


html,body {
    height: 100%;
}
#wrap {
    min-height: 100%;
    height: auto !important;
    margin: 0 auto -200px;
}
 #push
   height: 200px;
 }
 .footer {
    border-top: 1px solid #e5e5e5;
    color: #777;
    padding: 19px 0;
    background-color: #f5f5f5;
}


html,body的高度必须是100%,也就是充满浏览器窗口高度

#wrap div的min-height必须是100%,height呢,就自动适应。

关键点在于margin,top的外边距为0,而bottom的外边距则为-200px。

注意,就是-200px,理论上是footer高度(你可以通过firebug调试最佳高度)的负数,这一点也很关键!为什么要为负数呢?因为warp的高度本来就是100%,为负数的话,就可以为footer留出显示完整的高度,否则footer将出现在页面滚动条下部。

#push元素,页面完整显示的时候,似乎看不出来push元素的作用,但当你页面缩放时,如果没有push,footer元素就会和container中的元素重合,之前图上也有说明,那么其具体作用如何呢?通过firebug我们选中push的div,可以看到其正好包含着footer元素内容,如此将会阻止footer和container元素重合。

如此,以上关键点就介绍完了,你只要注意以下元素的分布,就可以轻松搞定bootstrap的粘页脚效果!


warp

push

三、实例讲解(有navbar-fixed-top)


①、核心代码

<head>
<link type="text/css" rel="stylesheet" href="/ymeng/components/bootstrap/css/bootstrap.css" />
<style type="text/css">
html {
  position: relative;
  min-height: 100%;
}
body {
  margin-bottom: 200px;
}
 .footer {
        border-top: 1px solid #e5e5e5;
    color: #777;
    padding: 19px 0;
    background-color: #f5f5f5;
    position: absolute;
    bottom: 0;
    width: 100%;
    height: 200px;
}
    </style>
<title>发布项目</title>
</head>
<body>
    <nav class="navbar navbar-default navbar-fixed-top">
    </nav>
    <div class=" container project_choose">
        <div class="row">
        </div>
    </div>
</div>
<div class="footer ">
    <div class="container">
    </div>
</div>
</body>
</html>


②、页面body布局


<body>

   <nav class="navbar navbar-default navbar-fixed-top">

   </nav>

   <div class=" container">


   </div>


   <div class="footer ">


   </div>

</body>

1

2

3

4

5

6

7

8

9

10

11

与第一种无navbar-fixed-top区别在于:


body中不再嵌入wrap,并列元素分别为nav(导航),container,footer

并且去掉push的div

③、css分析


html {

 position: relative;

 min-height: 100%;

}

body {

 margin-bottom: 200px;

}

.footer {

       border-top: 1px solid #e5e5e5;

   color: #777;

   padding: 19px 0;

   background-color: #f5f5f5;

   position: absolute;

   bottom: 0;

   width: 100%;

   height: 200px;

}


与第一种无navbar-fixed-top区别在于:


html的最小高度为100%,而不再是wrap 。

html的位置为relative(相对),而footer的位置为absolute(绝对),非常关键。

body的margin-bottom为footer的高度200px。

ok,之前做了第一种,目前换为第二种,更加简洁,推荐。


相关文章
|
前端开发 容器
Bootstrap 粘页脚,你必须得学会的简单技能(1)
Bootstrap 粘页脚,你必须得学会的简单技能
122 0
Bootstrap 粘页脚,你必须得学会的简单技能(1)
|
前端开发 容器
Bootstrap 粘页脚,你必须得学会的简单技能(2)
Bootstrap 粘页脚,你必须得学会的简单技能
169 0
|
前端开发 容器
Bootstrap 粘页脚,你必须得学会的简单技能
版权声明:欢迎转载,请注明沉默王二原创。 https://blog.csdn.net/qing_gee/article/details/50987126 Bootstrap 粘页脚(你必须得学会的简单技能),说得具体一点就是“将固定高度的页脚紧贴页面底部”。
1167 0
|
4月前
|
前端开发
Bootstrap5 文字排版3
Bootstrap 5 默认字体大小为 16px,行高 1.5,字体族为 &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif。所有元素默认上边距为 0,下边距为 1rem (16px)。HTML 标题(h1 至 h6)和代码元素(code、kbd、pre)均有预设样式,方便快速开发和一致的视觉效果。
|
4月前
|
移动开发 前端开发
Bootstrap5 文字排版1
Bootstrap 5 的默认文字排版设置包括:font-size 为 16px,line-height 为 1.5,font-family 为 &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif。所有元素的 margin-top 为 0,margin-bottom 为 1rem。HTML 标题(h1 至 h6)和 .h1 至 .h6 类均定义了样式,还有 .display-1 至 .display-4 类用于更大的标题样式。small 元素用于创建更小且颜色更浅的文本。
|
4月前
|
前端开发
Bootstrap5 文字排版2
Bootstrap 5 默认字体大小为 16px,行高 1.5,字体系列为 &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif。所有 HTML 标题(h1 至 h6)均有预设样式,段落默认上下间距为 16px。此外,Bootstrap 5 还提供了高亮文本、缩写、引用块和描述列表等元素的样式定义。
|
前端开发
bootstrap 导航,情境,字体图标
控件禁用 以button控件为例,下面两句都可以。效果为控件变灰,hover状态下鼠标指针变为禁止标志。 &lt;button type="button" disabled="disabled"&gt;i'm a button&lt;/button&gt; &lt;button type="button" disabled=&gt;i'm another button&lt;/bu
1176 0
Bootstrap5 徽章(Badges)2
以下是各种颜色类型的徽章示例,包括主要、次要、成功、危险、警告、信息、浅色和深色等不同风格的徽章。
Bootstrap5 徽章(Badges)4
徽章可以嵌入到其他元素中,如按钮。
Bootstrap5 徽章(Badges)1
Bootstrap5 徽章(Badges)用于突出显示新的或未读的项。通过在 `&lt;span&gt;` 元素上添加 `.badge` 类和颜色类(如 `.bg-secondary`),可以轻松创建徽章。

热门文章

最新文章