如何將導(dǎo)航欄始終固定在窗口頂部_html/css_WEB-ITnose
Jun 24, 2016 am 11:41 AM
如何將導(dǎo)航欄始終固定在窗口頂部:
在很多的網(wǎng)站導(dǎo)航欄或者類似于導(dǎo)航欄的一些功能一直能夠固定在網(wǎng)頁的頂部,就算是下拉滾動(dòng)條也不會(huì)被窗口所遮擋,這樣的功能往往非常的使用,下面就簡單介紹一下如何實(shí)現(xiàn)此種功能。先看一段代碼實(shí)例:
<!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下樣式,加下劃線表示只針對(duì)ie6 的hack */ _position:absolute;/* 把導(dǎo)航欄位置定義為絕對(duì)位置 關(guān)鍵*/ _top:expression(documentElement.scrollTop + "px"); /* 把導(dǎo)航欄位置放在瀏覽器垂直滾動(dòng)條的頂端 關(guān)鍵 */ z-index:9999; /* 讓導(dǎo)航欄浮在網(wǎng)頁的高層位置,遇到flash和圖片時(shí)候也能始終保持最外層 */ 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="#">前臺(tái)專區(qū)</a></li> <li class="menu"><a href="#">后臺(tái)專區(qū)</a></li> <li class="menu"><a href="#">交流專區(qū)</a></li> </ul></div><div id="main">大家拖動(dòng)滾動(dòng)條下吧 我很長 這樣就能看到導(dǎo)航欄固定的效果了 </div></body></html>
上面的代碼已經(jīng)實(shí)現(xiàn)了需要的功能,導(dǎo)航條固定在了網(wǎng)頁的頂部,這個(gè)主要是使用了position:fixed,然后將top值設(shè)置為0即可,但是僅僅使用position:fixed還是不夠,因?yàn)镮E6瀏覽器并不支持,所以還需要進(jìn)行瀏覽器兼容性設(shè)置,那就是添加以下代碼即可:
_position:absolute;/* 把導(dǎo)航欄位置定義為絕對(duì)位置 關(guān)鍵*/_top:expression(documentElement.scrollTop + "px"); /* 把導(dǎo)航欄位置放在瀏覽器垂直滾動(dòng)條的頂端 關(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 ?? ??? ???? ?? ??? ??? ???? ?? ?? ?? ? ???? ?? ??? ????????. 1. ????? ??? ??? ????? ?? ? ?? ?? (? : ??, ??, ???)? ?? ??? ?????. 2. JavaScript? ?? ?? ? ??? ???? ID? ?? ??? ?? ??? ??? ???? ?? ? ????. 3. CSS? ???? ???, ???, ?? ??? ? ??/?? ?? ??? ???? ???? ??? ???? ??? ??? ??????. 4. ???? ????????? : ???? ? ??? ????? ??? ???? JS ???? ???? ????? ???? ??? ???? ??? ??? ??? ???? ??? ?????. ??? ???????

HTMLHEAD? ?? ???? SEO, ?? ?? ? ???? ??? ?????. 1. ??? ??? ??? ????, ???? ???? ???? ??????. 2. OpenGraph ? Twitter ?? ??? ???? ?? ?? ??? ????? ??? ?????? ???? ??? ??? ???? ???????. 3. ?? ?? ? ??? ??? ???? ??? ??? ??? ???? ????????. 4. ?? ???, ?? ?? ? ?? ?? ?? ???? ?? ??? ??? ????? ???????.

Tolearnhtmlin2025, chooSeatUtoriorialThatthatthath and-practicewithmoderndardAndardsandegratescssandjavaScriptBasics.1.

???? ??? HTML ?? ???? ??? ??? ?????? ?? Div Flex ?? ??? ????? ???? ??? ?????? ??? ???????. ??, ?? ???? ?????? ?? CSS? ?? ? ?? ????. ?? ?? ??? ALT ??? ?? ???? ?? URL? ?????? ??? ???? ??? ?? TD? ??????????. ????? ?? ?????? ?? ??? ????? ???????.

HTML ??? ???? ????? ?? ?? ???? ??? ?? ???? ?? ???? ?? ? ? ????. 1. ??, ??? ?? ?? ??? ?? ??? ? ??? ???? ???? ? ?????. 2. ?? ???? ???? ??? ? ?? ??? ?? ? ? ????. 3. ??? ??? ??? ???? ?????? ??? ??? ? SEO ??? ??????. 4. ??? ??? ?, ??? ??? ??? ????? ??????, ???? ?? ????? ???? ??? ?? ???? ???? ???????. 5. ??? ??? ALT ??? ??? ????. 6. ??? ???? ??? ?? ??? ?? ?? ??? ?? ? ? ????. ? ? ?? ??? ???? ???? ?? ???? ???? ?? ? ???? ???? ? ??????.

??? ??? ??? HTML ?? ??? ??? ????? ?? ?? ?? ?? ???? ?? ?? ? ? ????. ?? ???? ??? ?????. 1. JavaScript? ???? ?? ?? ? ??? ???? ???? ?? ?? ??? ?? ?? ? ???? ???? ????. 2. Formspree? ?? ?? ???? ? ???? ???? ???? ???? ??? ?? ? ???? ??? ?????. 3. LocalStorage? ???? ??? ?? ??? ????? ?? ??? ?? ???? ??? ???? ? ????? ??? ??? ?? ???? ???? ????.

???, ID, ???, ??? ? ??? HTML?? ?? ????? ???? ??? ?????. ???? ??? ?? ? JavaScript ??? ?????? ?? ?? ??? ??? ??? ???? ? ?????. ID? ?? ?? ? JavaScript ???? ??? ??? ?? ?? ???? ?????. ???? ???? ??? ???? ?? ? ? ??? ?? ???? ????? ??? ???? ???? ????. ??? ??? ??? ?? ???? ???? ? ????, ?? ??? ?? ? ??? ?? ??? ?????. ??? ??? ?? ????? ???? ? ????? ???? ??? ????? ?? ?????. ??? ??? ????? ???? ?? ???? ??? ??? ???? ? ????.

Native Lazy Loading? ?? ???? ????,?? = "???"??? ??? ???? ??? ????? ? ? ????. 1. JavaScript ?? ?? ?????? ???? ??? HTML?? ?? ?????. 2. ??? ??? ? ?? ??? ???? ?? ??, ?? ??? ??? ??? ? ? ?? ???? ?????. 3. ? ?? ?? ?? ???????? ???? ???? ????. 4. ??? ??? ?, ??? ?? ???? ???? ??? ??? ?? ???????. 5. SRCSET ? ?? ??? ?? ?? ? ??? ??? ????????. 6. ??? ??? ???????. ?? ??? ??????? ???? ????. ?? ??? ?? ??? ? ??? JavaScript ???? ?? ? ? ????.
