Heim  >  Artikel  >  Web-Frontend  >  用div+css实现简单下拉菜单效果_html/css_WEB-ITnose

用div+css实现简单下拉菜单效果_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 12:28:591379Durchsuche

实现自定义下拉菜单,看下面吧,CSS都已经注释。

在风格管理里面添加下面的CSS,直接把下面 CSS代码 复制到风格最底部即可:

css代码:/*下拉菜单样式*/

*{margin:0;padding:0;border:0;}
#div_center { width:790px; height:23px; background:#003399; margin-left: auto;margin-right:auto;} /*定义总体宽度、高度;background:003399; 控制背景颜色,居中对齐*/
#nav { line-height: 20px; list-style-type: none; margin-top:5px;}         /*控制一级菜单行高;上边距5px;*/  
#nav a { display: block; width: 77px; text-align:center; font-size:12px;} /*一级菜单链接总体样式:每个菜单的宽,居中对齐,文字大小*/
#nav a:link { color:#FFF; text-decoration:none;margin:0;}     /* 未访问的链接 */  
#nav a:visited {color:#FFF;text-decoration:none;margin:0;}    /* 已访问的颜色 */
#nav a:hover {color:#C00;text-decoration:none;}                /* 鼠标在链接上 */

#nav li {float: left;}                   /* 一级菜左对齐 */
#nav li a:hover{background:#FFFFFF;}     /* 鼠标在一级菜单上改变其背景色 */
#nav li ul {line-height: 24px; background:#FFF; list-style-type: none;text-align:left;left: -999em; width:132px; position: absolute;border-width: 1px;border-top-style: none;border-right-style: solid;border-bottom-style: solid;border-left-style: solid;border-color: #003399; padding:1px;}             /*二级菜单总体样式:行高24px;背景颜色;外框宽度;相对位置;边框一个象素,上边没样式,左右下边实线,边框颜色#003399;内边距1个象素*/

#nav li ul a{display:block; width: 130px;text-align:left;padding-left:2px;}                 /* 二级菜单链接样式;背景宽度、左对齐,左缩进2 */
#nav li ul a:link {color:#0d5097; text-decoration:none;}                                   /* 未访问的链接 */
#nav li ul a:visited {color:#0d5097;text-decoration:none;}                                 /* 已访问的链接 */
#nav li ul a:hover {color:#FFF;text-decoration:none;font-weight:normal;background:#003399;}/* 鼠标在链接上 */

#nav li:hover ul {left: auto;}
#nav li.sfhover ul {left: auto;}
#content {clear: left;}

把下面代码插入模板里面,你想要显示的地方:

DIV代码:

上面的连接地址自己进行修改了。

实现的效果如下:

效果图

是不是很简单呢!

在补充一句,如果要在IE上面整个居中,就要在模板最顶部加上下面的代码,我在 Firefox 可以不加,但在IE上就要加哦:

补充代码

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn