GIF動態效果:
代碼部分:
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <script src="jquery.js"></script> <style> .dropdown { position: relative; display: inline-block; height: 30px; width: 70px; background-color: red; text-align: center; font-size: 15px; } .dropdown:hover { position: relative; display: inline-block; height: 30px; width: 70px; background-color: blue; text-align: center; font-size: 15px; } .dropdown-content { display: none; position: absolute; height: 30px; width: 70px; background-color: red; text-align: center; z-index: 1; font-size: 15px; } .dropdown:hover .dropdown-content { display: block; height: 120px; width: 70px; background-color: red; text-align: center; font-size: 15px; top: 30px; } .dropdown1 { position: relative; display: inline-block; height: 30px; width: 70px; background-color: red; text-align: center; font-size: 15px; } .dropdown1:hover { position: relative; display: inline-block; height: 30px; width: 70px; background-color: blue; text-align: center; font-size: 15px; } .dropdown-content1 { display: none; position: absolute; height: 30px; width: 70px; background-color: red; text-align: center; z-index: 1; font-size: 15px; } .dropdown1:hover .dropdown-content1 { display: block; height: 120px; width: 70px; background-color: red; text-align: center; font-size: 15px; top: 30px; } .dropdown2 { position: relative; display: inline-block; height: 30px; width: 70px; background-color: red; text-align: center; font-size: 15px; } .dropdown2:hover { position: relative; display: inline-block; height: 30px; width: 70px; background-color: blue; text-align: center; font-size: 15px; } .dropdown-content2 { display: none; position: absolute; height: 30px; width: 70px; background-color: red; text-align: center; z-index: 1; font-size: 15px; } .dropdown2:hover .dropdown-content2 { display: block; height: 120px; width: 70px; background-color: red; text-align: center; font-size: 15px; top: 30px; } </style> </head> <body> <div class="dropdown"> <table type> <tr><td><span>首頁</span></td></tr> </table> <div class="dropdown-content"> <p>這是菜單1</p> <p>這是菜單2</p> <p>這是菜單3</p> </div> </div> <div class="dropdown1"> <table> <tr><td><span>首頁</span></td></tr> </table> <div class="dropdown-content1"> <p>這是菜單1</p> <p>這是菜單2</p> <p>這是菜單3</p> </div> </div> <div class="dropdown2"> <table> <tr><td><span>首頁</span></td></tr> </table> <div class="dropdown-content2"> <p>這是菜單1</p> <p>這是菜單2</p> <p>這是菜單3</p> </div> </div> </body> </html>
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <script src="jquery.js"></script> <style> .two_bar { margin-left:80px; display:none; } li { list-style:none; } .two_bar li,.one_bar { display:block; text-align:center; font-size:16px; background-color:#55339e; color:#ffffff; border-bottom:1px solid #ffffff; border-radius:10px; line-height:38px; overflow:hidden; height:38px; width:70px; } a:link,a:visited,a:hover,a:active { text-decoration:none; } </style> </head> <div class="top_bar"> <ul> <a href="###" class="one_bar">首頁</a> <ul class="two_bar"> <li>這是菜單1</li> <li>這是菜單1</li> <li>這是菜單1</li> </ul> <a href="###" class="one_bar">首頁</a> <ul class="two_bar"> <li>這是菜單1</li> <li>這是菜單1</li> <li>這是菜單1</li> </ul> <a href="###" class="one_bar">首頁</a> <ul class="two_bar"> <li>這是菜單1</li> <li>這是菜單1</li> <li>這是菜單1</li> </ul> </ul> </div> <script type="text/javascript"> $(function(){ $(document).ready(function(){ $(".one_bar").hover(function(){ $(this).next().slideToggle(); $(this).parent().siblings().children("ul").slideUp(); }); }); }); </script> </body> </html>