目录
一、导航
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> <style> *{ margin: 0; padding: 0; } /*方案一:转化为行级块*/ /*.menu{ font-size: 0; } .menu>li{ list-style: none; display: inline-block; border: 1px solid red; font-size: 14px; }*/ /*方案二:设置浮动*/ .bgback{ position: relative; background-color: #000; } .menu{ height: 40px; padding: 4px 0; } .nav{ position: absolute; left: 0; top: 40px; padding: 4px 0; height: auto; display: none; z-index: 1; } .menu:after,.nav:after,.nav_child:after{ content: " "; position: absolute; width: 100%; height: 4px; left: 0; bottom: 0; /*border-bottom: 3px solid red;*/ /*background: linear-gradient(to right,red,green,blue,orangered,deeppink,chocolate,gold);*/ /*用角度设置*/ /*background: linear- gradient(0deg,red,green,blue,orangered,deeppink,chocolate,gold);*/ background: linear- gradient(90deg,red,green,blue,orangered,deeppink,chocolate,gold); } .menu:before,.nav:before,.nav_child:before{ content: " "; position: absolute; width: 100%; height: 4px; left: 0; top: 0; /*border-bottom: 3px solid red;*/ /*background: linear-gradient(to right,red,green,blue,orangered,deeppink,chocolate,gold);*/ /*background: linear- gradient(0deg,red,green,blue,orangered,deeppink,chocolate,gold);*/ background: linear- gradient(90deg,red,green,blue,orangered,deeppink,chocolate,gold); } .menu>li{ /*设置等宽的导航*/ /*width: 100px; text-align: center;*/ /*根据内容设置宽度*/ position: relative; padding: 0 50px; color: #fff; list-style: none; float: left; height: 40px; line-height: 40px; text-align: center; cursor: pointer; } .menu>li:hover{ background-color: white; color: black; } .nav>li{ list-style: none; width: 118px; text-align: left; padding: 10px; position: relative; } .menu>li:hover>.nav{ color: white; } .nav>li:hover{ background-color: white; color: black; } .nav:after{ content: " "; position: absolute; width: 100%; height: 4px; left: 0; bottom: 0; background: linear- gradient(90deg,red,green,blue,orangered,deeppink,chocolate,gold); } .menu>li:hover>.nav{ display: block; } .nav_child { display: none; position: absolute; width: 100px; right: -100px; top: 0px; } .nav_child > li { list-style: none; padding: 0 20px 0 10px; color: white; background-color: black; } .nav_child > li:hover { color: black; background-color: white; } .nav > li:hover > .nav_child { color: #fff; display: block; } </style> </head> <body> <ul class="menu bgback"> <li>首页</li> <li>课程 <ul class="nav bgback"> <li>html1/css</li> <li>html5/css3</li> <li>javascript <ul class="nav_child"> <li>数据库</li> <li>JSP</li> <li>java</li> </ul> </li> <li>vue</li> </ul> </li> <li>社交活动</li> <li>联系我们</li> <li>论坛</li> </ul> </body> </html>
二、简单导航
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> <style> *{ margin: 0; padding: 0; } .menu{ height: 40px; } .menu>li{ /*margin-left: -1px;*/ list-style: none; float: left; width: 100px; height: 40px; text-align: center; line-height: 40px; border: 1px solid black; box-sizing: border-box; box-shadow: 0 0 1px black; } .nav>li{ list-style: none; border: 1px solid black; box-sizing: border-box; height: 40px; text-align: center; padding-left: 10px; } .nav{ display: none; } .menu>li:hover>.nav{ display: block; } .menu>li:hover,.nav>li:hover,.nav_child>li:hover{ background-color: aliceblue; } .nav_child{ margin-left: 87px; margin-top: -40px; display: none; } .nav_child>li{ width: 100px; height: 40px; list-style: none; border: 1px solid black; padding-left: -10px; } .nav>li:hover>.nav_child{ display: block; } </style> </head> <body> <ul class="menu"> <li>动态</li> <li>博客</li> <li>分类专栏 <ul class="nav"> <li>c语言</li> <li>java</li> <li>JSP</li> <li>前端 <ul class="nav_child"> <li>html</li> <li>css</li> <li>javascript</li> <li>vue</li> </ul> </li> <li>数据库</li> </ul> </li> <li>Bink</li> <li>更多</li> </ul> </body> </html>