站长资源网页制作

CSS中的导航栏和下拉菜单的实现

整理:jimmy2024/10/6浏览2
简介一、CSS导航栏(1)导航栏的作用熟练使用导航栏,对于网站排版非常重要,使用CSS你可以转换成好看的导航栏而不是枯燥的HTML菜单。(2)垂直导航栏<1>代码如下 垂直导航栏<</div> <div class="news_infos"><div id="MyContent"><p><strong>一、CSS导航栏</strong></p> <p><strong>(1)导航栏的作用</strong></p> <p>熟练使用导航栏,对于网站排版非常重要,使用CSS你可以转换成好看的导航栏而不是枯燥的HTML菜单。</p> <p><strong>(2)垂直导航栏</strong></p> <p><1>代码如下</p> <div class="htmlcode"> <pre class="brush:xhtml;"> <!doctyre html> <html> <head> <meta charset="utf-8"> <title>垂直导航栏</title> <link rel="stylesheet" href="daohanglan1.css"/> </head> <body> <ul> <li><a class="active" href="#home">主页</a></li> <li><a href="#news">新闻</a></li> <li><a href="#contact">联系</a></li> <li><a href="#about">关于</a></li> </ul> <div> <h2>垂直导航栏</h2> <h3>垂直导航栏垂直导航栏垂直导航栏垂直导航栏垂直导航栏垂直导航栏垂直导航栏</p> <p>垂直导航栏</p> <p>垂直导航栏</p> <p>垂直导航栏</p> <p>垂直导航栏</p> <p>垂直导航栏</p> <p>垂直导航栏</p> <p>垂直导航栏</p> </div> </body> </html> body{ margin:0; } ul{ padding:0; margin:0; list-style-type:none; width:25%; background-color:#f1f1f1; position:fixed; height:100%; top:0; overflow:auto; /* border:1px solid #000; */ } /* ul>li:not(:last-child){ border-bottom:1px solid #000; } */ ul a{ display:block; text-decoration:none; color:#000; padding:8px 16px; text-align:center; } li a:hover:not(.active){ background-color:#555; color:white; } a.active{ background-color:#4caf50; color:white; } div{ margin-left:25%; padding:1px 16px; height:100px; }</pre> </div> <p><2>效果图如下:</p> <p><a href="javascript:;" onclick="showimg('/UploadFiles/2021-03-30/2018071815040510.gif');"><img src="/UploadFiles/2021-03-30/2018071815040510.gif" alt="CSS中的导航栏和下拉菜单的实现" onmousewheel="return bbimg(this)" onload="javascript:resizepic(this)" border="0"/></a></p> <p><strong>(3)水平导航栏</strong></p> <p><1>代码如下:</p> <div class="htmlcode"> <pre class="brush:xhtml;"> <!doctyre html> <html> <head> <meta charset="utf-8"> <title>水平导航栏</title> <link rel="stylesheet" href="daohanglan2.css"/> </head> <body> <ul> <li><a class="active" href="#home">主页</a></li> <li><a href="#news">新闻</a></li> <li><a href="#contact">联系</a></li> <li style="float:right"><a href="#about">关于</a></li> </ul> <div class="box"> <h2>水平导航栏</h2> <p>水平导航栏;水平导航栏;水平导航栏;水平导航栏</p> <p>水平导航栏;水平导航栏;水平导航栏;水平导航栏</p> <p>水平导航栏;水平导航栏;水平导航栏;水平导航栏</p> <p>水平导航栏;水平导航栏;水平导航栏;水平导航栏</p> <p>水平导航栏;水平导航栏;水平导航栏;水平导航栏</p> <p>水平导航栏;水平导航栏;水平导航栏;水平导航栏</p> <p>水平导航栏;水平导航栏;水平导航栏;水平导航栏</p> <p>水平导航栏;水平导航栏;水平导航栏;水平导航栏</p> <p>水平导航栏;水平导航栏;水平导航栏;水平导航栏</p> <p>水平导航栏;水平导航栏;水平导航栏;水平导航栏</p> <p>水平导航栏;水平导航栏;水平导航栏;水平导航栏</p> <p>水平导航栏;水平导航栏;水平导航栏;水平导航栏</p> <p>水平导航栏;水平导航栏;水平导航栏;水平导航栏</p> <p>水平导航栏;水平导航栏;水平导航栏;水平导航栏</p> <p>水平导航栏;水平导航栏;水平导航栏;水平导航栏</p> <p>水平导航栏;水平导航栏;水平导航栏;水平导航栏</p> <p>水平导航栏;水平导航栏;水平导航栏;水平导航栏</p> <p>水平导航栏;水平导航栏;水平导航栏;水平导航栏</p> <p>水平导航栏;水平导航栏;水平导航栏;水平导航栏</p> <p>水平导航栏;水平导航栏;水平导航栏;水平导航栏</p> </div> </body> </html> body{ margin:0; } ul{ padding:0px; margin:0px; list-style-type:none; background-color:#333; overflow:hidden; position:fixed; top:0px; width:100%; } ul>li{ float:left; border-right:1px solid #fff; display:inline; } ul>li:last-child{ border-right:none; } a{ padding:14px 16px; display:block; width:60px; text-align:center; text-decoration:none; color:white; } li a:hover:not(.active) { background-color: #111; } li a.active { color: white; background-color: #4CAF50; } .box{padding:20px; margin-top:30px; background-color:#1abc9c; height:1500px;}</pre> </div> <p><2>效果图如下:</p> <p><a href="javascript:;" onclick="showimg('/UploadFiles/2021-03-30/2018071815040511.gif');"><img src="/UploadFiles/2021-03-30/2018071815040511.gif" alt="CSS中的导航栏和下拉菜单的实现" onmousewheel="return bbimg(this)" onload="javascript:resizepic(this)" border="0"/></a></p> <p><strong>二、下拉菜单</strong></p> <p><strong>(1)下拉菜单的作用</strong></p> <p>下拉菜单可以使你的网页不在枯燥,可以通过css改变网页的美观,这也是网页排版必不可少的东西。</p> <p><strong>(2)下拉菜单</strong></p> <p><1>代码如下:</p> <div class="htmlcode"> <pre class="brush:xhtml;"> <!doctype html> <html> <head> <meta charset="utf-8"/> <title></title> <link rel="stylesheet" type="text/css" href="xialacaidan.css"/> </head> <body> <div class="dropdown"> <span> 下拉菜单 </span> <div class="di"> <ul> <li>你好!</li> <li>我好!</li> <li>大家好!</li> </ul> </div> </div> </body> </html> body{ margin:0; text-align:center; } .dropdown{ background-color:green; text-align:center; padding:20px; display:inline-block; cursor:pointer; position:relative; } .di{ display:none; position:absolute; top:61px; left:0; } .di ul{ list-style:none; padding:0; margin:0; background-color: #f9f9f9; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); } .di ul li{ min-width:104px; padding:10px 15px; } .dropdown:hover{ background-color:#3e8e41 } .dropdown:hover .di{ display:block; } .di ul li:hover{ background-color: #f1f1f1 }</pre> </div> <p><2>效果图如下</p> <p><a href="javascript:;" onclick="showimg('/UploadFiles/2021-03-30/2018071815040512.gif');"><img src="/UploadFiles/2021-03-30/2018071815040512.gif" alt="CSS中的导航栏和下拉菜单的实现" onmousewheel="return bbimg(this)" onload="javascript:resizepic(this)" border="0"/></a></p> <p>以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。</p></div> </div> </div> <div class="share"> </div> <div class="nextinfo"> <p>上一篇:<a href="http://m.paidiu.com/show/1/70970.html" title="CSS清除浮动方法大全(小结)">CSS清除浮动方法大全(小结)</a></p> <p>下一篇:<a href="http://m.paidiu.com/show/1/70972.html" title="HTML+CSS实现下拉菜单的实现">HTML+CSS实现下拉菜单的实现</a></p> </div> <div class="otherlink"> <h2>最新资源</h2> <ul> <li><a href="/show/1/615856.html" title="何洛洛.2024-别叫醒我(EP)【光羽】【FLAC">何洛洛.2024-别叫醒我(EP)【光羽】【FLAC</a></li> <li><a href="/show/1/615855.html" title="林忆莲.1996-爱莲说2CD【华纳】【WAV+CUE">林忆莲.1996-爱莲说2CD【华纳】【WAV+CUE</a></li> <li><a href="/show/1/615854.html" title="黄妃.2005-红【亚律】【WAV+CUE】">黄妃.2005-红【亚律】【WAV+CUE】</a></li> <li><a href="/show/1/615853.html" title="刘美麟《同生》[FLAC/分轨][161.95MB]">刘美麟《同生》[FLAC/分轨][161.95MB]</a></li> <li><a href="/show/1/615852.html" title="群星《前途海量 电影原声专辑》[320K/MP3">群星《前途海量 电影原声专辑》[320K/MP3</a></li> <li><a href="/show/1/615851.html" title="群星《前途海量 电影原声专辑》[FLAC/分轨">群星《前途海量 电影原声专辑》[FLAC/分轨</a></li> <li><a href="/show/1/615850.html" title="张信哲.1992-知道新曲与精丫巨石】【WAV+">张信哲.1992-知道新曲与精丫巨石】【WAV+</a></li> <li><a href="/show/1/615849.html" title="王翠玲.1995-ANGEL【新艺宝】【WAV+CUE】">王翠玲.1995-ANGEL【新艺宝】【WAV+CUE】</a></li> <li><a href="/show/1/615848.html" title="景冈山.1996-我的眼里只有你【大地唱片】">景冈山.1996-我的眼里只有你【大地唱片】</a></li> <li><a href="/show/1/615847.html" title="群星《八戒 电影原声带》[320K/MP3][188.">群星《八戒 电影原声带》[320K/MP3][188.</a></li> </ul> </div> </div> <div class="sidebar"> <div class="cloud"><h2 class="hometitle">一句话新闻</h2><a href="/show/1/603537.html"><ul>Windows上运行安卓你用过了吗<br><br>在去年的5月23日,借助Intel Bridge Technology以及Intel Celadon两项技术的驱动,Intel为PC用户带来了Android On Windows(AOW)平台,并携手国内软件公司腾讯共同推出了腾讯应用宝电脑版,将Windows与安卓两大生态进行了融合,PC的使用体验随即被带入到了一个全新的阶段。</ul></a></div> </div> </article> <footer> <p style="font-size: 14px;">友情链接:<a href="http://www.imxmx.com/" title="杰晶网络" target="_blank">杰晶网络</a> <a href="http://www.ddrfans.com/" title="DDR爱好者之家" target="_blank">DDR爱好者之家</a> <a href="http://www.nqxw.com/" title="南强小屋" target="_blank">南强小屋</a> <a href="/" title="黑松山资源网" target="_blank">黑松山资源网</a> <a href="http://www.dyhadc.com/" title="白云城资源网" target="_blank">白云城资源网</a> <a href="/sitemap.xml">SiteMap</a></p> <p>Design by <a href="http://m.paidiu.com">黑松山资源网</a> <a href="/">http://m.paidiu.com</a></p> </footer> <script src="/images/nav.js"></script> <script type="text/javascript"> jQuery.noConflict(); jQuery(function() { var elm = jQuery('#left_flow2'); var startPos = jQuery(elm).offset().top; jQuery.event.add(window, "scroll", function() { var p = jQuery(window).scrollTop(); jQuery(elm).css('position', ((p) > startPos) ? 'fixed' : ''); jQuery(elm).css('top', ((p) > startPos) ? '0' : ''); }); }); </script> </body> </html>