DIV固定浮动在网页顶端或底部代码

1、DIV固定浮动在网页顶端代码

<div style="position:fixed; top:0; z-index:100">top</div>

说明:要使div里的文本居中,增加“width:100%; text-align:center;”即可(下同)。

2、DIV固定浮动在网页底部代码

<div style="position:fixed; bottom:0; z-index:100">bottom</div>

完整示例

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>DIV</title>
<style type="text/css">body{margin:0; padding:0;}</style>
</head>

<body>
    <div style="position:fixed; top:0; z-index:100;">top</div>
    <div style="height:2000px; background-color:#A8A8B7">hello,world!</div>
    <div style="position:fixed; bottom:0; z-index:100;">bottom</div>
</body>
</html>


评论: 0 | 引用: 0 | 查看次数: 12088
发表评论
登录后再发表评论!