新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
純css代碼實(shí)現(xiàn)簡單下拉菜單效果
實(shí)現(xiàn)方法:
(推薦教程:CSS教程)
1、用ul 和 li標(biāo)簽寫一個關(guān)聯(lián)結(jié)構(gòu)(ul 和 li的父子關(guān)系渾然天成,一般的關(guān)聯(lián)結(jié)構(gòu)都用它們)
2、對界面進(jìn)行初始化(萬金油式開頭)
*{ padding: 0; margin: 0; }
3、給ul 和 a標(biāo)簽添加樣式(這里大家可以自由發(fā)揮)
ul,a{ font-size: 20px; list-style: none; text-decoration: none; background-color: #3C3C3C; color: #FFFFFF; width: 100px; text-align: center; border: 0px solid black; border-radius: 5px; /*圓角*/ margin-top: 1px; } a{ display: block; }
4、將.plat部分的內(nèi)容隱藏起來
.plat{ display: none; }
5、(重頭戲來了) 對第一個a標(biāo)簽用:hover選擇器;實(shí)現(xiàn)功能:當(dāng)鼠標(biāo)劃過a標(biāo)簽時,隱藏部分內(nèi)容可見
.nav:hover .plat{ display: block; clear: both; }
6、至此功能已經(jīng)實(shí)現(xiàn),大家可以自己添加樣式來優(yōu)化用戶體驗(yàn)
例如:
菜單欄橫向排列:
.nav{ float: left; margin-left: 1px; }
鼠標(biāo)滑過欄目,提醒其位置
`.plat li:hover>a{ background-color: dimgrey; }`
效果:
(學(xué)習(xí)視頻推薦:css視頻教程)
全部代碼:
Document
分享文章:純css代碼實(shí)現(xiàn)簡單下拉菜單效果
本文URL:http://fisionsoft.com.cn/article/chejoc.html