通過下面的代碼,我創建了一個固定的<header>
,它由<image>
和<navigation>
組成。現在我想添加子菜單<navigation>
,您可以在<button>
和<SlideItem>
部分看到。出現在主菜單下的jQuery幻燈片菜單
幻燈片功能迄今爲止完美。但是,它確實出現在主菜單的旁邊,而不是在其下面。它似乎卡在按鈕的<li>
內。
我需要在我的代碼中更改什麼,所以sub-menus
出現在主菜單下方?
$(document).ready(function() {
$(".button").mouseenter(function() {
$(this).children(".SlideItem").slideDown(500);
});
$(".button").mouseleave(function() {
$(this).children(".SlideItem").slideUp(500);
});
});
body {
margin: 0;
}
.header {
width: 80%;
height: 10%;
margin-left: 10%;
display: flex;
justify-content: space-between;
position: fixed;
top: 0;
box-sizing: border-box;
border-style: solid;
border-width: 1px;
background-color: yellow;
}
.image {
width: 30%;
height: 100%;
display: flex;
justify-content: center;
text-align:center;
align-items: center;
box-sizing: border-box;
border-style: solid;
border-width: 1px;
background-color: green;
}
.navigation {
width: 70%;
height: 100%;
box-sizing: border-box;
border-style: solid;
border-width: 1px;
}
ul {
height: 100%;
display: flex;
list-style: none;
margin: 0;
padding: 0;
box-sizing: border-box;
border-style: solid;
border-width: 1px;
background-color: blue;
}
li {
width: 100%;
display: flex;
justify-content: center;
text-align:center;
align-items: center;
box-sizing: border-box;
border-style: solid;
border-width: 1px;
}
.content{
width: 80%;
margin-top: 10%;
margin-left: 10%;
box-sizing: border-box;
border-style: solid;
border-width: 1px;
background-color: red;
}
.SlideItem {
display: none;
}
.SlideItem {
box-sizing: border-box;
border-style: solid;
border-width: 1px;
background-color: lime;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="header"> \t
<div class="image">
Image
</div>
<nav class="navigation">
<ul>
<li class="button"> 1.0 Main Menu
<ul class="SlideItem">
<li> 1.1 Sub Menu </li>
<li> 1.2 Sub Menu </li>
<li> 1.3 Sub Menu </li>
</ul>
</li>
<li> 2.0 Main Menu </li>
<li> 3.0 Main Menu </li>
</ul>
</nav>
</div>
您也可以找到我的代碼here。
可以定位子菜單絕對讓比例出該元素的。 – Gezzasa