如何將導(dǎo)航欄始終固定在窗口頂部_html/css_WEB-ITnose
Jun 24, 2016 am 11:41 AM
如何將導(dǎo)航欄始終固定在窗口頂部:
在很多的網(wǎng)站導(dǎo)航欄或者類似于導(dǎo)航欄的一些功能一直能夠固定在網(wǎng)頁的頂部,就算是下拉滾動條也不會被窗口所遮擋,這樣的功能往往非常的使用,下面就簡單介紹一下如何實現(xiàn)此種功能。先看一段代碼實例:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <title>螞蟻部落</title> <style type="text/css">*{ padding:0px; margin:0px;}body, ul, li{ background-color:white; font-size:12px; font-family:Arial, Helvetica, sans-serif; text-align:center;}#main{ width:20px; height:1000px; margin:0px auto; background-color:#CCC;}#nav{ width:500px; margin:0px auto; position:fixed;/*固定作用*/ top:0px; left:490px; /*ie6下樣式,加下劃線表示只針對ie6 的hack */ _position:absolute;/* 把導(dǎo)航欄位置定義為絕對位置 關(guān)鍵*/ _top:expression(documentElement.scrollTop + "px"); /* 把導(dǎo)航欄位置放在瀏覽器垂直滾動條的頂端 關(guān)鍵 */ z-index:9999; /* 讓導(dǎo)航欄浮在網(wǎng)頁的高層位置,遇到flash和圖片時候也能始終保持最外層 */ text-align:left;}a{ color:#000000; text-decoration:none;}.menu{ width:120px; height:18px; margin:0px 4px 0px 0px; background-color:#F5F5F5; color:#999999; border:1px solid #EEE8DD; padding:6px 0px 0px 0px; overflow-y:hidden; cursor:hand; display:inline; list-style:none; font-weight:bold; float:left;}</style></head><body><div id="nav"> <ul> <li class="menu"><a href="#">前臺專區(qū)</a></li> <li class="menu"><a href="#">后臺專區(qū)</a></li> <li class="menu"><a href="#">交流專區(qū)</a></li> </ul></div><div id="main">大家拖動滾動條下吧 我很長 這樣就能看到導(dǎo)航欄固定的效果了 </div></body></html>
上面的代碼已經(jīng)實現(xiàn)了需要的功能,導(dǎo)航條固定在了網(wǎng)頁的頂部,這個主要是使用了position:fixed,然后將top值設(shè)置為0即可,但是僅僅使用position:fixed還是不夠,因為IE6瀏覽器并不支持,所以還需要進行瀏覽器兼容性設(shè)置,那就是添加以下代碼即可:
_position:absolute;/* 把導(dǎo)航欄位置定義為絕對位置 關(guān)鍵*/_top:expression(documentElement.scrollTop + "px"); /* 把導(dǎo)航欄位置放在瀏覽器垂直滾動條的頂端 關(guān)鍵 */
原文地址是:http://www.51texiao.cn/div_cssjiaocheng/2015/0503/589.html
最為原始地址是:http://www.softwhy.com

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

HTML?? ??? ??? ????? ???? ??? ?? ???, ??? ? SEO ??? ?? ? ? ????. 1. ??? ????? ??? ?? ??? ? ??? ??? ????? ?? ????????. 2. ????? ??? ???? ?? ?? ???? ???? ???? ?? ??? ?????. 3. ? ???? ??? ?? ??? ????? ??? ? ?? ?? ?? ?? ????? ?? ??? ????. ?? ???? ??? ??????? ?? ??? ??? ??? ???? ???? ??? ??? ?? ??? ???? ???????.

? ??? ??? Core HTML ???? ???????. 1. ???? ?? ??? ?? ??? ???? ??? ???? ?? ?? ? ?? ??? ?????. 2. ??? ??? ?? ?? ? SEO? ???? ?? ?? (-), ?? () ? ?? ?? (? :)? ?????. 3. ?????? ???? ????, ????? ???? ??? ???? ????? ?? Aria-Current ??? ???? ?????. 4. ?? ?? ???? ?? ??? ?? ? ?? ??? ?????. ??? ??? ???? ???? ??? ???, ?? ?? ? ?? ?? ???? ?? ? ? ????.

HTML ?? ??? ???? ?? ??? ??? ???? ?? ?? ?? ? ???? ?? ??? ????????. 1. ????? ??? ??? ????? ?? ? ?? ?? (? : ??, ??, ???)? ?? ??? ?????. 2. JavaScript? ?? ?? ? ??? ???? ID? ?? ??? ?? ??? ??? ???? ?? ? ????. 3. CSS? ???? ???, ???, ?? ??? ? ??/?? ?? ??? ???? ???? ??? ???? ??? ??? ??????. 4. ???? ????????? : ???? ? ??? ????? ??? ???? JS ???? ???? ????? ???? ??? ???? ??? ??? ??? ???? ??? ?????. ??? ???????

?? ?? ??? ???? ???? ?? ?? ??? ?? ??? ???? ?? HTML? ?????. ???? ?? ??? ????. : ?? ??; ② ?? ??? ??????. ③ ???? ????. ④ ?? ?? ??; ⑤ ?? ???? ?????. metadata? ?????. ? ??? OR? ?? ??? ?? ?????. XHTML ???? ?? ?? HTML ????? HTML5? ??? ?????. ??? ???? ??? ????? ?? ?? ? ??? ??? ? ????. ??? ???? ???? ?? Hello? ???????. ?? ?? ??? ???? ???? ??? ???? ????? ???? ??? ??? ?? ?? ???? ???? ??????.

?? ?? ???? HTML?? ??? ?? ???? ??????. ???? ??? ?? ??? ???? ??? ?? ??? ??? ?? ?? ??? ???? ????. 1. ??, ???, ??? ?? ?? ??? ???? ????. 2. ??, ???? ?? ?? ??? ???? ????. 3. ?? ?? ???? ?? ? ??? ???? ?? ?????. ?? ??? ??? ?????. ? ?? ??? ??? ??? ?? ???? ? ? ????. style ???? ???? ??? CSS ?? ?? ?????? ?? ???????. Select2? ?? ????? ??? ????? ? ??? ? ????.

?? ? ??? ????? ??? ?? ???? ? ???? ?? ???? HTML ?? ??? ?? ?? ? ? ????. 1. ??? ???? ?? ??? webvtt ???? ???? ??, srclang ? ??? ??? ??????. 2. ?? ??? ?? ?? ?? ??? ???? ?? ??? ???? ?? ??? ??????. 3. ?? ??? JavaScript? ?? ?? ?? ??? ??????? ??? ??? ?? ???? ??? ? ????. 4. ?? ???? ???? ??? ???? ?? ???? ???? ?? ???? ???, ?? ?? ? ?? ?????????.

HTML ?? ??? ???? ?? ??? ????? ??? ?? ???????. 1. ??? ??? ???? SRC? ALT ? IMG? HREF? ???????. 2. ?? ??? ???? ?? ??, ??? ??????? ?? ?? ?? ??? ??? ??? ?? ??? ???? ??????. 3. ???? ??? ?? ? ??? ???? ?? MDN ??? ???? ?? ? ??? CSS? ???? ?? ?? ???? ?? ???? ???????. 4. ?? ??? ??? ????? ? Metacharset = "UTF-8"? ???? ??? UTF-8 ???? ???? ??????.
