css實現橫嚮導航和豎嚮導航欄的方法(代碼)

來源:互聯網
上載者:User
本篇文章給大家帶來的內容是關於css實現橫嚮導航和豎嚮導航欄的方法(代碼),有一定的參考價值,有需要的朋友可以參考一下,希望對你有所協助。

一、豎嚮導航

<!DOCTYPE html><html><head><meta charset="utf-8"><style>ul{list-style-type:none;margin:0;padding:0;}a{display:block;background-color:green;color:white;width:80px;text-align:center;padding:4px;text-decoration:none;}a:hover,a:active{background-color:#98bf21;}</style></head><body><ul><li><a herf="">首頁</a></li><li><a herf="">學習中心</a></li><li><a herf="">考試中心</a></li><li><a herf="">考試動態</a></li></ul></body></html>

運行結果:

二、橫嚮導航:

<!DOCTYPE html><html><head><meta charset="utf-8"><style>ul{list-style-type:none;margin:0;padding:0;overflow:hidden;}li{float:left;}a{display:block;background-color:pink;color:white;width:80px;text-align:center;padding:4px 0px;text-decoration:none;}a:hover,a:active{background-color:gray;}</style></head><body><ul><li><a herf="">首頁</a></li><li><a herf="">學習中心</a></li><li><a herf="">考試中心</a></li><li><a herf="">考試動態</a></li></ul></body></html>

運行結果:

注意:

1、a標籤的display=block讓連結是一個可點擊的地區而不是文本。

2、a連結指定為block塊元素之後可以設定寬度,讓每個連結的寬度看起來一樣。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.