使用CSS制作4级下拉菜单

本文介绍了如何使用CSS技术创建4级下拉菜单,强调了CSS在下拉菜单制作中的优势,如代码简洁易懂,无需依赖JavaScript。通过CSS进行定位和样式控制,使得下拉菜单的实现变得更加简便。

如今的web页面对下拉菜单的需求是越来越广泛了。从单纯的一层下拉菜单到多层菜单。下拉菜单的制作方式也非常多元化。在CSS还没有得到很好普及前,大家通常使用javascript来控制。以便达到下拉菜单的显示效果。由于javascript代码制作下拉菜单比较复杂,导致很多使用下拉菜单的web页面制作者的困惑。对定位。对色彩的控制都不能很容易的掌控。 随着css技术的普及和日益发展,使用css制作下拉菜单也逐渐得以推广。而且得到了广泛的应用。由于不使用任何javascript脚本控制,完全由css来控制,使得代码更加简洁并得以理解。下面我就给大家介绍一个纯css制作的4级下拉菜单

 

<style type="text/css">
/**/
body
{font:normal 9pt verdana,sans-serif;color:#000;}

.menu 
{
height
:150px;
font-size
:90%;
margin
:25px 0 50px 15px; /* this page only */
}


/* remove all the bullets, borders and padding from the default list styling */
.menu ul 
{
position
:relative;
z-index
:500;
padding
:0;
margin
:0;
list-style-type
:none;
width
:150px;
}

/* style the list items */
.menu li 
{
background
:#d4d8bd;
height
:26px;
/* for IE7 */
float
:left;
}

.menu li.sub 
{background:#d4d8bd url(http://www.programmer.com.cn/images/sub.gif) no-repeat right center;}  

/* get rid of the table */
.menu table 
{position:absolute; border-collapse:collapse; top:0; left:0; z-index:100; font-size:1em;}

/* style the links */
.menu a, .menu a:visited 
{
display
:block; 
text-decoration
:none;
height
:25px;
line-height
:25px;
width
:149px;
color
:#000;
text-indent
:5px;
border
:1px solid #fff;
border-width
:0 1px 1px 1px;
}

/* hack for IE5.5 */
* html .menu a, * html .menu a:visited 
{width:150px; width:149px;}
/* style the link hover */
* html .menu a:hover 
{color:#efa; background:#aa7; position:relative;}

.menu li:hover 
{position:relative;}

/* For accessibility of the top level menu when tabbing */
.menu a:active, .menu a:focus 
{color:#efa; background:#aa7;}

/* retain the hover colors for each sublevel IE7 and Firefox etc */
.menu li:hover > a 
{color:#efa; background:#aa7;}
 
/* hide the sub levels and give them a positon absolute so that they take up no room */
.menu li ul 
{
visibility
:hidden;
position
:absolute;
top
:-30px;
/* set up the overlap (minus the overrun) */
left
:100px;
/* set up the overrun area */
padding
:30px;
/* this is for IE to make it interpret the overrrun padding */
background
:transparent;
}


/* for browsers that understand this is all you need for the flyouts */
.menu li:hover > ul 
{visibility:visible;}


/* for IE5.5 and IE6 you need to style each level hover */

/* keep the third level+ hidden when you hover on first level link */
.menu ul a:hover ul ul
{
visibility
:hidden;
}

/* keep the fourth level+ hidden when you hover on second level link */
.menu ul a:hover ul a:hover ul ul
{
visibility
:hidden;
}

/* keep the fifth level hidden when you hover on third level link */
.menu ul a:hover ul a:hover ul a:hover ul ul
{
visibility
:hidden;
}


/* make the second level visible when hover on first level link */
.menu ul a:hover ul 
{
visibility
:visible;
}

/* make the third level visible when you hover over second level link */
.menu ul a:hover ul a:hover ul
{ 
visibility
:visible;
}

/* make the fourth level visible when you hover over third level link */
.menu ul a:hover ul a:hover ul a:hover ul 
{ 
visibility
:visible;
}

/* make the fifth level visible when you hover over fourth level link */
.menu ul a:hover ul a:hover ul a:hover ul a:hover ul 
{ 
visibility
:visible;
}


/*]]>*/
</style>
< div  class ="menu" >
< ul >
< li >< href ="#" > dropdown menu </ a ></ li >

< li >< href ="#" > dropdown menu </ a ></ li >
< li  class ="sub" >< href ="#" > dropdown menu <!-- [if IE 7]><! --> </ a > <!-- <![endif] -->
<!-- [if lte IE 6]><table><tr><td><![endif] -->
    
< ul >
    
< li >< href ="#" > dropdown menu </ a ></ li >
    
< li  class ="sub" >< href ="#" > dropdown menu <!-- [if IE 7]><! --> </ a > <!-- <![endif] -->
    
<!-- [if lte IE 6]><table><tr><td><![endif] -->
        
< ul >

            
< li >< href ="#" > dropdown menu </ a ></ li >
            
< li >< href ="#" > dropdown menu </ a ></ li >
            
< li  class ="sub" >< href ="#" > dropdown menu <!-- [if IE 7]><! --> </ a > <!-- <![endif] -->
            
<!-- [if lte IE 6]><table><tr><td><![endif] -->
                
< ul >
                    
< li >< href ="#" > dropdown menu1 </ a ></ li >
                    
< li  class ="sub" >< href ="#" > dropdown menu2 <!-- [if IE 7]><! --> </ a > <!-- <![endif] -->

                    
<!-- [if lte IE 6]><table><tr><td><![endif] -->
                        
< ul >
                            
< li >< href ="#" > dropdown menu11 </ a ></ li >
                            
< li >< href ="#" > dropdown menu22 </ a ></ li >
                            
< li >< href ="#" > dropdown menu33 </ a ></ li >
                            
< li >< href ="#" > dropdown menu44 </ a ></ li >
                            
< li >< href ="#" > dropdown menu55 </ a ></ li >

                        
</ ul >
                    
<!-- [if lte IE 6]></td></tr></table></a><![endif] -->
                    
</ li >
                    
< li >< href ="#" > dropdown menu </ a ></ li >
                    
< li >< href ="#" > dropdown menu </ a ></ li >
                
</ ul >
            
<!-- [if lte IE 6]></td></tr></table></a><![endif] -->
            
</ li >

        
</ ul >
    
<!-- [if lte IE 6]></td></tr></table></a><![endif] -->
    
</ li >
    
< li >< href ="#" > dropdown menu </ a ></ li >
    
</ ul >
<!-- [if lte IE 6]></td></tr></table></a><![endif] -->
    
</ li >
< li >< href ="#" > dropdown menu </ a ></ li >
< li >< href ="#" > dropdown menu </ a ></ li >

< li >< href ="#" > dropdown menu </ a ></ li >

</ ul >
</ div >
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值