最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

詳解八種方法實(shí)現(xiàn)CSS頁面底部固定

  發(fā)布時間:2019-01-08 15:33:20   作者:w3cbest   我要評論
這篇文章主要介紹了詳解八種方法實(shí)現(xiàn)CSS頁面底部固定的相關(guān)資料,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

當(dāng)我們在寫頁面時經(jīng)常會遇到頁面內(nèi)容少的時候,footer會戳在頁面中間或什么?反正就是不在最底部顯示,反正就是很難看,下面要講的布局就是解決如何使元素粘住瀏覽器底部,

方法一:footer高度固定+絕對定位

html

<div class="dui-container">
<header>Header</header>
<main>Content</main>
<footer>Footer</footer>
</div>

CSS

.dui-container{
position: relative;
min-height: 100%;
}
main {
padding-bottom: 100px;
}
header, footer{
line-height: 100px;
height: 100px;
}
footer{
width: 100%;
position: absolute;
bottom: 0
}

查看效果

方法二:在主體content上的下邊距增加一個負(fù)值等于底部高度

html

<header>Header</header>
<main>Content</main>
<footer>Footer</footer>

CSS

html, body {
height: 100%;
}
main {
min-height: 100%;
padding-top: 100px;
padding-bottom: 100px;
margin-top: -100px;
margin-bottom: -100px;
}
header, footer{
line-height: 100px;
height: 100px;
}

查看效果

方法三:將頁腳的margin-top設(shè)為負(fù)數(shù)

html

<header>Header</header>
<main>Content</main>
<footer>Footer</footer>

CSS

main {
min-height: 100%;
padding-top: 100px;
padding-bottom: 100px;
}
header, footer{
line-height: 100px;
height: 100px;
}
header{
margin-bottom: -100px;
}
footer{
margin-top: -100px;
}

查看效果

方法四: 通過設(shè)置flex,將footer的margin-top設(shè)置為auto

html

<header>Header</header>
<main>Content</main>
<footer>Footer</footer>

CSS

body{
display: flex;
min-height: 100vh;
flex-direction: column;
}
header,footer{
line-height: 100px;
height: 100px;
}
footer{
margin-top: auto;
}

查看效果

方法五: 通過函數(shù)calc()計(jì)算內(nèi)容的高度

html代碼

<header>Header</header>
<main>Content</main>
<footer>Footer</footer>

CSS代碼

main{
min-height: calc(100vh - 200px); /* 這個200px是header和footer的高度 */
}
header,footer{
height: 100px;
line-height: 100px;
}

查看效果

方法六: 通過設(shè)置flexbox,將主體main設(shè)置為flex

html

<header>Header</header>
<main>Content</main>
<footer>Footer</footer>

CSS代碼

body{
display: flex;
min-height: 100vh;
flex-direction: column;
}
main{
flex: 1
}

查看效果

方法七: 使用grid布局

Html代碼

<header>Header</header>
<main>Content</main>
<footer>Footer</footer>

CSS代碼

html {
height: 100%;
}
body {
min-height: 100%;
display: grid;
grid-template-rows: auto 1fr auto;
}
.footer {
grid-row-start: 3;
grid-row-end: 4;
}

查看效果

方法八: display-*

html

<header>Header</header>
<main>Content</main>
<footer>Footer</footer>

CSS

body {
  min-height: 100%;
  display: table;
  width: 100%;
}
main {
  display: table-row;
  height: 100%;
}

查看效果

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • css實(shí)現(xiàn)背景漸變與底部固定的藍(lán)天白云示例

    漸變背景的的設(shè)定:通過定義body實(shí)現(xiàn);動態(tài)在低端的白云:設(shè)定了body_foot1和body_foot1中的循環(huán)圖片顯示定義,以及div動態(tài)底端的設(shè)定,具體實(shí)現(xiàn)如下,感興趣的朋友可以參
    2013-06-24
  • div footer標(biāo)簽css實(shí)現(xiàn)位于頁面底部固定

    Web頁面的“footer”部分隨著飄上來,處在頁面的半腰中間,給視覺效果帶來極大的影響,讓你的頁面看上去很不好看,特別是現(xiàn)在寬屏越來越多,這種現(xiàn)象更是常見,本文將介紹兩
    2012-12-02

最新評論

肥东县| 镇宁| 石林| 斗六市| 桂阳县| 湖口县| 江源县| 中江县| 论坛| 克东县| 会宁县| 闽侯县| 德保县| 江安县| 大兴区| 鸡西市| 吉安市| 双牌县| 洞口县| 兴安县| 平昌县| 尉犁县| 平顺县| 买车| 吉木萨尔县| 沙洋县| 景德镇市| 邹城市| 颍上县| 昌图县| 庆城县| 翁源县| 原平市| 恩平市| 河西区| 神农架林区| 广安市| 溧阳市| 大足县| 蚌埠市| 潜江市|