最近整理了CSS導航欄及彈窗,具體如下:
CSS導航
先來看下效果:

<!doctype html> <html> <head> <title>Insert your title</title> <meta charset="utf-8"> <style> body{ font-size:12px; } #discuss{ width:990px; margin:0 auto; } #mt{ /*高度:30px,邊框,上邊框,背景顏色*/ height:30px; border:1px solid #ddd; border-top:2px solid #9d9d9d; background:#F7F7F7; } #discuss-content{ border-bottom:1px solid #ddd; padding-bottom:2px; } #discuss-datas{ width:990px; } #discuss-datas thead td{ /*加粗,上下內邊距,下邊框,文本居中對齊*/ font-weight:bold; padding:5px 0; border-bottom:1px solid #ddd; text-align:center; color:#666; } /*處理 .col1 的樣式 (每行第一列的效果)*/ #discuss-datas td.col1{ width:620px; text-align:left; } /*內容行中所有的列*/ #discuss-datas tbody td{ /*虛線下邊框,上下內邊距,文本水平居中對齊,文本顏色*/ border-bottom:1px dotted #ddd; padding:5px 0; text-align:center; color:#9c9a9c; } /*處理所有超鏈接*/ #discuss a{ color:#005aa0; text-decoration:none; } #discuss a:hover{ text-decoration:underline; } /*曬,論 兩幅圖*/ #discuss-datas b{ /*寬度,高度,背景屬性*/ padding-left:21px; padding-bottom:2px; padding-top:3px; background-image:url(../Images/iconlist_1.png); background-repeat:no-repeat; margin-right:5px; } b.shai{ background-position:-110px -220px; } b.lun{ background-position:-152px -220px; } /*2017-01-09 浮動練習*/ #mt a{ float:left; width:100px; height:30px; text-align:center; line-height:30px; } #mt a.current{ /*左右上邊框,背景顏色,文本顏色*/ border:1px solid #ddd; border-bottom:none; border-top:2px solid #E4393C; background-color:#fff; color:#E4393C; /*位置上調:margin-top 給負值*/ margin-top:-6px; height:35px; line-height:35px; } #extra p{margin:0;} /*方案1*/ /*#extra p.new{ float:left; } #extra p.total{ float:right; } #extra{ overflow:hidden; }*/ /*方案2*/ #extra p.total{ float:right; } </style> </head> <body> <!-- 練習 --> <!-- #discuss : width:990px --> <div id="discuss"> <!-- 頁簽 #mt : height:30px; ,邊框,背景 --> <div id="mt"> <a href="#">網友討論圈</a> <a href="#" class="current">曬單帖</a> <a href="#">討論帖</a> <a href="#">圈子帖</a> <a href="#">問答帖</a> </div> <!-- 內容 #discuss-content : 下邊框 --> <div id="discuss-content"> <!-- 表格 --> <table id="discuss-datas"> <thead> <tr> <td class="col1">主題</td> <td>回復/瀏覽</td> <td>作者</td> <td>時間</td> </tr> </thead> <tbody> <tr> <td class="col1"> <b class="shai"></b> <a href="#"> 好大一瓶,不錯 </a> </td> <td>0/0</td> <td> <a href="#">2001年冬天</a> </td> <td> 2011-11-11 11:11:11 </td> </tr> <tr> <td class="col1"> <b class="lun"></b> <a href="#"> 好大一瓶,不錯 </a> </td> <td>0/0</td> <td> <a href="#">2001年冬天</a> </td> <td> 2011-11-11 11:11:11 </td> </tr> <tr> <td class="col1"> <b class="shai"></b> <a href="#"> 好大一瓶,不錯 </a> </td> <td>0/0</td> <td> <a href="#">2001年冬天</a> </td> <td> 2011-11-11 11:11:11 </td> </tr> <tr> <td class="col1"> <b class="lun"></b> <a href="#"> 好大一瓶,不錯 </a> </td> <td>0/0</td> <td> <a href="#">2001年冬天</a> </td> <td> 2011-11-11 11:11:11 </td> </tr> </tbody> </table> <!-- 其他內容(略) --> <div id="extra"> <p class="total"> 共900個話題 <a href="#">瀏覽全部話題</a> </p> <p class="new"> 有問題與其他用戶討論 <a href="#">[發表帖子]</a> </p> </div> </div> </div> </body> </html> 最后效果圖:

商城導航:

<!doctype html> <html> <head> <title>Insert your title</title> <meta charset="utf-8"> <style> #nav{ /*寬度,高度,背景顏色,水平居中對齊*/ width:990px; height:40px; background-color:#E64346; margin:0 auto; } #nav p{ /*取消默認margin,寬度,高度,背景顏色*/ margin:0; width:210px; height:40px; background-color:#CD2A2C; } #nav>p>a{ /*左浮動,高度,行高,文字:加粗,大小,顏色,取消下劃線*/ float:left; height:40px; line-height:40px; font-weight:bold; font-size:14px; color:#fff; text-decoration:none; padding-left:15px; } #nav>p>b{ /*右浮動,寬度,高度,背景,位置*/ float:right; width:20px; height:20px; background:url(../Images/iconlist_2.png) no-repeat -65px 0; margin:10px 10px 0 0; } #nav>p{ float:left; } #nav>ul{ float:left; margin:0; padding:0; list-style:none; } #nav>ul li{ float:left; } #nav>ul li a{ /*寬度,高度,行高,文本:水平居中,大小,顏色,下劃線,加粗*/ float:left; width:100px; height:40px; line-height:40px; text-align:center; font-size:14px; color:#fff; text-decoration:none; font-weight:bold; } #nav>ul li a:hover{ background-color:#BD2A2C; } #container{ width:990px; min-height:200px; margin:0 auto; } #cate_box{ margin:0; padding:0; list-style:none; /*寬度,高度,背景顏色,左右下邊框*/ width:210px; min-height:400px; background-color:#FAFAFA; border:2px solid #CD2A2C; border-top:none; box-sizing:border-box; /*上內邊距*/ padding-top:5px; } #cate_box>li{ /*左內邊距,上下內邊距,寬度,下邊框(白色)*/ padding:5px 0 5px 10px; width:196px; box-sizing:border-box; border-bottom:1px solid #fff; border-top:1px solid transparent; } #cate_box li:hover{ border-top-color:#ddd; border-bottom-color:#ddd; background-color:#fff; } #cate_box li>a{ color:#333; text-decoration:none; font-size:14px; } </style> </head> <body> <nav id="nav"> <p> <a href="#">全部商品分類</a> <b></b> </p> <ul> <li> <a href="#">首頁</a> </li> <li> <a href="#">服裝城</a> </li> <li> <a href="#">食品</a> </li> <li> <a href="#">團購</a> </li> <li> <a href="#">奪寶島</a> </li> <li> <a href="#">閃購</a> </li> <li> <a href="#">金融</a> </li> </ul> </nav> <div id="container"> <ul id="cate_box"> <li> <a href="#">圖書、音像、數字商品</a> </li> <li> <a href="#">家用電器</a> </li> </ul> </div> </body> </html> 導航列表彈框效果:
初始狀態:

鼠標懸停時:

<!doctype html> <html> <head> <title>Insert your title</title> <meta charset="utf-8"> <style> #my_jd{ width:100px; height:30px; text-align:center; line-height:30px; border:1px solid #000; background-color:#fff; /*相對定位:配合 #menu 的絕對定位*/ position:relative; cursor:pointer; } #menu{ width:400px; height:100px; background-color:#fff; border:1px solid #000; /*絕對定位*/ position:absolute; top:30px; left:-1px; /*隱藏*/ display:none; } #my_jd:hover #menu{ display:block; } #my_jd:hover #line{ width:100px; position:absolute; border-top:1px solid #fff; } </style> </head> <body> <div id="my_jd"> 我的京東 <!-- 彈出菜單 --> <div id="menu"> 模擬我的京東彈出菜單 </div> <div id="line"></div> </div> </body> </html> 以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。
新聞熱點
疑難解答