CSS中position属性有4种可选值:static,relative,absolute,fixed,用于定位html元素的位置,并影响元素块生成的方式。这里向大家描述一下position:fixed 的使用,此属性元素的定位方式同absolute类似,但它的包含块是视区本身。
先看代码:
<!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=gb2312" /> <title>无标题文档</title> <style> body{ width:100%; height:1350px; margin:0; } .heade input{ background-color:#FFFFFF; width:700px; height:30px; font-size:24px; position:fixed; left:300px; } .heade span{ font-family:"宋体"; font-size:24px; color:#0033FF; position:fixed; left:1010px; } </style> </head> <body> <div class="heade"> <input type="text"/> <span class="span">搜索</span> </div>
</body> </html>你只需要把指定的div设置成fixed就可以实现浮动的效果,方便有快捷!
来自:http://blog.csdn.net/lb228988/article/details/21451509