html css jquery練習(簡單漂亮的紅色二級菜單)

來源:互聯網
上載者:User

<html>
<head>
<style type="text/css">

.list{
width:800px;
height:40px;
background-color:#D5000A;
border-radius:5px;
box-shadow:-2px 2px 5px black;
margin:auto;
text-align:left;
}

.nav{
list-style:none;
}

ul.nav li{
float:left;
padding:5px 10px;
cursor:pointer;
position:relative;
}

ul.nav li a{
color:white;
width:75px;
height:20px;
text-align:center;
line-height:20px;
padding: 5px;
display:block;
font-size:14px;
text-decoration:none;
}

ul.nav li a:hover{
border-radius:5px;
background-color:#AD0007;
}

ul.nav li a.current{
border-radius:5px;
background-color:#AD0007;
}

ul.sub_nav {
display:none;
position:absolute;
padding: 0 0 10px 0;
background: #D5000A;
border-radius: 0 0 5px 5px;
left: 0;
top: 40px;
box-shadow: #333 0 1px 1px;
}

ul.sub_nav li{
float:none;
list-style:none;
}
</style>
</head>
<body>
<div class="list">

<ul class="nav">
<li><a class="current">首頁</a></li>

<li><a href="#">電子商務</a>
<ul class="sub_nav">
<li><a href="#">電子商務</a></li>
<li><a href="#">子功能表二</a></li>
<li><a href="#">子功能表三</a></li>
<li><a href="#">子功能表四</a></li>
</ul>
</li>

<li><a href="#">網路營銷</a>
<ul class="sub_nav">
<li><a href="#">網路營銷</a></li>
<li><a href="#">子功能表二</a></li>
<li><a href="#">子功能表三</a></li>
<li><a href="#">子功能表四</a></li>
</ul>
</li>

<li><a href="#">客服服務</a>
<ul class="sub_nav">
<li><a href="#">子功能表一</a></li>
<li><a href="#">子功能表二</a></li>
<li><a href="#">子功能表三</a></li>
<li><a href="#">子功能表四</a></li>
</ul>
</li>

<li><a href="#">工程案例</a>
<ul class="sub_nav">
<li><a href="#">子功能表一</a></li>
<li><a href="#">子功能表二</a></li>
<li><a href="#">子功能表三</a></li>
<li><a href="#">子功能表四</a></li>
</ul>
</li>

<li><a href="#">行業資訊</a>
<ul class="sub_nav">
<li><a href="#">子功能表一</a></li>
<li><a href="#">子功能表二</a></li>
<li><a href="#">子功能表三</a></li>
<li><a href="#">子功能表四</a></li>
</ul>
</li>

<li><a href="#">聯絡我們</a>
<ul class="sub_nav">
<li><a href="#">子功能表一</a></li>
<li><a href="#">子功能表二</a></li>
<li><a href="#">子功能表三</a></li>
<li><a href="#">子功能表四</a></li>
</ul>
</li>

</ul>
<script type="text/javascript" src="jquery-1.7.2.js"></script>
<script type="text/javascript">
$(".nav li").mouseover(function(){
$(this).find('ul').slideDown();});
$(".nav li").mouseleave(function(){
$(this).find('ul').slideUp();});
</script>
</div>
</body>
</html>

 

 


Tips:

從應用的角度來說,relative常用於包含有absolute元素的容器元素上。 
absolute元素預設以body做為容器元素進行絕對位置。 
如果你想在頁面一個特定地區進行絕對位置,就可以在absolute元素外包裹一層容器元素應用relative樣式。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.