鼠標經(jīng)過時的狀態(tài)是通過交換背景圖片來實現(xiàn)的,使用的是a:hover 的樣式。這是詳細的代碼: 以下內(nèi)容為程序代碼 #navcontainer a:hover { background: url(bg_navbutton_over.gif); color: #A5003B; text-decoration: none; } 顏色的設置是通過改變Color屬性的,而text-decoration: none;是用來防止正規(guī)的鏈接中的下劃線出現(xiàn)的。通常狀況下,為了使你的導航欄能表現(xiàn)的更清晰,更具體,所以我又添加了一個額外的樣式current,這個用來顯示當前網(wǎng)站所處的頁面。代碼如下: 以下內(nèi)容為程序代碼 #navcontainer li a#current { background: url(bg_navbutton_over.gif); color: #A5003B; text-decoration: none; } 這個樣式的定義用在導航欄里的鏈接里(li a),屬性和值都和經(jīng)過狀態(tài)時是一樣的。 現(xiàn)在剩下僅有的事情就是把這個ID添加到我們的html代碼里了: 以下內(nèi)容為程序代碼 div id="navcontainer" ul li a href="#" id="current" Home /a /li li a href="#" About me /a /li li a href="#" Contact me /a /li li a href="#" Articles /a /li li a href="#" Photo roll /a /li /ul /div 觀看最后的結(jié)果
#footer h2 a:hover { color: #F7F7F6; text-decoration: none; border-bottom: none; background-color: #A5003B; } 我們用了一人上h2標簽為我們的文本: div id="footer" h2 .... /h2 /div 我們添加這點兒代碼在緊挨"#container" id的DIV下面,換句話講是在 body 結(jié)束的上面! 然后我們添加這個JavaScript代碼,這是必需的對于確保這個網(wǎng)頁腳在Safari上顯示時緊貼瀏覽器的底部。 以下內(nèi)容為程序代碼 !-- function getWindowHeight() { var windowHeight = 0; if (typeof(window.innerHeight) == 'number') { windowHeight = window.innerHeight; } else { if (document.documentElement document.documentElement.clientHeight) { windowHeight = document.documentElement.clientHeight; } else { if (document.body document.body.clientHeight) { windowHeight = document.body.clientHeight; } } } return windowHeight; } function setFooter() { if (document.getElementById) { var windowHeight = getWindowHeight(); if (windowHeight 0) { var contentHeight = document.getElementById('container').offsetHeight; var footerElement = document.getElementById('footer'); var footerHeight = footerElement.offsetHeight; if (windowHeight - (contentHeight + footerHeight) = 0) { footerElement.style.position = 'relative'; footerElement.style.top = (windowHeight - (contentHeight + footerHeight)) + 'px'; } else { footerElement.style.position = 'static'; } } } } window.onload = function() { setFooter(); } window.onresize = function() { setFooter(); } //--
注意:一定要確保在你提交到javascript里的ID在你的內(nèi)容里也有同樣的ID名稱
如果你現(xiàn)在瀏覽我們的到目前為止的網(wǎng)頁,你將看到在Safari瀏覽器上網(wǎng)頁腳并不顯示出來,怎么回事呢?不太確定的說法是因為我們有兩個浮動的 containers (#left and #content)在它上面,需要被清除掉,我以前曾經(jīng)寫了一篇文章關(guān)于這種現(xiàn)像,但Eric Meyer發(fā)表了一篇更完整的關(guān)于這個內(nèi)容的文章,將這些事解釋的更清楚! 為了調(diào)整這個,我們需要添加一個清除上面的DIV: 以下內(nèi)容為程序代碼 div /div 我們添加了這個樣式: 以下內(nèi)容為程序代碼 .clear { clear: both; }這是最后的結(jié)果 下一個部分我們將介紹在左側(cè)的導航欄下添加喜歡的鏈接,希望你能學到更多喲!這是我們教程的最后一部分,我們將添加喜歡的鏈接在左側(cè)并且鏈接我們的樣式在一個單獨的CSS樣式單里。
添加XHTML代碼 首先,我們要添加xhtml代碼為我們喜歡的鏈接: 以下內(nèi)容為程序代碼 div id="favlinks" h2 My Favorite Sites /h2 ul li a Stopdesign /a /li li a SimpleBits /a /li li a Mezzoblue /a /li li a Zeldman /a /li /ul /div 在開始我們把我們的鏈接放進一個DIV容器里并給它一個ID名為“favlinks”。這個ID包含我們的鏈接和標題的,必須要通過樣式單來定義 width, margin 和 padding。對于這些鏈接,我們用一個class樣式因為這種方法我們可以重復使用它在我們的頁面上。所以你可以添加類似的帶有一個標題的鏈接列表。但如果你真的那樣做了,一定要確保它是被添加在“favlinks”容器的DIV里的,或者建立另一個DIV ID來包含這些鏈接以便保持每個無素處在正確的位置。