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塊元素之后可以設置寬度,讓每個鏈接的寬度看起來一樣。

相關推薦:

div css導航條(全屏css導航條)_html/css_WEB-ITnose

CSS圖片導航_html/css_WEB-ITnose

以上就是css實現橫向導航和豎向導航欄的方法(代碼)的詳細內容,更多請關注php中文網其它相關文章!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM