Home >Web Front-end >HTML Tutorial >How to fix a fixed area on the page? _html/css_WEB-ITnose

How to fix a fixed area on the page? _html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 12:07:461593browse

For example, if you open Taobao and scroll down, the search bar at the top will be fixed. .
Even if the cursor is placed on the search bar at the top and the mouse wheel is rolled, the page will still scroll
How to achieve it, it must be fully compatible, even with IE6


Reply to discussion (solution)

you can do it like this.

<!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" /><title>无标题文档</title><style>body{margin:0;height:2000px;}input{float:left;padding:0;margin:0;}.box{height:40px;padding:10px 0;background:#ccc; text-align:center; position:fixed;_position:absolute;width:100%;_top:expression(eval(document.documentElement.scrollTop));}.search{height:100%;width:410px;margin:0 auto;}.search .text{width:300px;height:28px;padding:4px 0 4px 6px;border:solid 2px blue;font-size:14px;line-height:30px;}.search .btn{background:blue;border:none;height:40px;width:100px;padding:0 10px;}</style></head><body><div class="box" id="box">	<div class="search">    	<input type="text"  class="text"/>        <input type="button" value="搜索"  class="btn"/>    </div></div></body></html>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn