首頁 > web前端 > css教學 > 主體

css控制div固定在瀏覽器底部實例代碼

高洛峰
發布: 2017-03-27 17:23:12
原創
1895 人瀏覽過

css控制div固定在瀏覽器底部

注意:此功能僅用於頁面高度較小頁面。

css控制div固定在瀏覽器底部實例代碼

程式碼如下:

<html>
<head>
<style type="text/css">
body{
  margin:0px;
}
#main{
  width:100%;
  height:50px;
  position:absolute;
  top:100%;
  margin-top:-50px;
  background:#360;
  color:white;
}
</style>
</head>
<body>
<div style="border:1px solid #f00;width:500px;height:1800px"></div>
<div id="main">bottom</div>
</body>
</html>
登入後複製

網路上找了個更好的:

當瀏覽器視窗無限縮小,向右拖曳滾動條不會出現空白。

css控制div固定在瀏覽器底部實例代碼

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<title>ie6层固定</title>
<style type="text/css">
<!--
.bookbox {
background-color: #09C;
height: 30px;
width: 100%;
position: fixed;
bottom: 0px;
left: auto;
right: auto;
line-height: 30px;
text-align: center;
_POSITION: absolute;/*兼容IE6*/
_TOP: expression(offsetParent.scrollTop+document.documentElement.clientHeight-this.offsetHeight);/*兼容IE6*/
}
.bookbox a{color: #FFF;}
-->
</style>
</head>
<body>
<div style="border:1px solid #f00;width:500px;height:2000px;">这个例子是实现层固定在浏览器窗口的最下面,兼容IE6.<br />
<br />
往下看,看页面的最下面</div>
<div class="bookbox">测试测试测试测试测试测试测试测试测试测试测试测试测试测试</div>
</body>
</html>
登入後複製

恩,感覺上面的對不是很好,這裡網路找了個,挺實用的:

css控制div固定在瀏覽器底部實例代碼

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
html, body {
    height: 100%;
    overflow-y: auto
}
body, div, p, ul, ol, li, form, input {
    padding: 0; margin: 0;
}
body{
    position:relative;
    background: #fff;
}
#wp {
    border:1px solid #00f;
    height: auto;
    min-height: 100%;
    _height: 100%;
}
#ft {
    border:1px solid #f00;
    margin-top: -157px;
    padding: 50px 0 0;
}
#sc {
    border:1px solid #f00;
    width: 580px;
    margin: 0 auto;
    padding-left: 20px;
    padding-bottom: 157px;
}
#s {
    border:1px solid #f00;
    position: relative;
    height: 33px;
    z-index:9
}
</style>
</head>
<body>
    <div id="wp">
        <div id="sc">
            <div id="s"></div>
        </div>
    </div>
    <div id="ft">
               
    </div>
</body>
</html>
登入後複製

以上是css控制div固定在瀏覽器底部實例代碼的詳細內容。更多資訊請關注PHP中文網其他相關文章!

來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!