2013-07-31 73 views
3

我想製作我的菜單,以便當我處於特定的窗口大小(如手機)時,我的菜單將轉換爲垂直下拉式手風琴菜單。我對媒體查詢和響應/自適應設計很熟悉,但我無法讓我的子菜單垂直放下/下滑,無論是懸停還是點擊。如何將具有垂直子菜單的水平菜單轉換爲具有子菜單的垂直手風琴菜單?

這裏是我的Fiddle

HTML:

<!--MENU UNDER HEADER BEGINS--> 
<table id="menubar" width="0" border="0" align="center" cellpadding="0" cellspacing="0"> 
    <tr> 
    <td> 

    <div id="navmenu"> <!--#navmenu DIV menu contents start here--> 
    <ul> 

<li>  
    <a href="index.php" class="mainlist">HOME</a> 
</li> 

<li> 
    <a href="about.php" class="mainlist">ABOUT ME</a> 
</li> 




<li class="slidedown">  
    <a href="graphicdesign.php" class="mainlist">GRAPHIC DESIGN</a> 
    <ul> 
    <li><a href="graphicdesign/hobbyist-independent.php">Hobbyist/Independent</a></li>  
    <li><a href="graphicdesign/job&amp;freelance.php">Job & FreeLance</a></li> 
    <li><a href="graphicdesign/universityatbuffalo.php">University At Buffalo</a></li> 
    </ul> 
</li> 


<li class="slidedown"> 
    <a href="webdesign.php" class="mainlist">WEB DESIGN</a> 
    <ul> 
    <li>Hobbyist/Independent</li> 
    <li>Job & FreeLance</li> 
    <li>University At Buffalo Website</a></li> 
    </ul> 
</li> 


<li class="slidedown"> 
    <a href="photography.php" class="mainlist">PHOTOGRAPHY</a> 
    <ul> 
    <li><a href="photography/hobbyist-independent.php">Hobbyist/Independent</a></li> 
    <li><a href="photography/job&amp;freelance.php">Job & Freelance</a></li> 
    <li><a href="photography/studentprojects.php">Student Projects</a></li> 
    </ul> 
</li> 


<li> 
    <a href="contactme.php" class="mainlist">CONTACT ME</a> 
</li> 

    </ul> 
    </div> <!--#navmenu DIV menu contents end here--> 

    </td> 
    </tr> 
</table> 
<!--menu under header ends--> 

CSS:

html, body { 
    height: 100%; 
    overflow-x:hidden; 
    overflow-y:hidde; 
    margin:auto; 
} 
#wrap { 
    margin:auto; 
    min-height: 100%; 
    background-image: url(style/flourish-bg.png); 
    background-repeat:no-repeat; 
    background-position: top center; 
    z-index:0; 
} 
#header { 
    width:1024px; 
    height:160px; 
    background-repeat: no-repeat; 
} 
#bgheader { 
    background-image: url(style/bgheader.jpg); 
    background-repeat:repeat-x; 
    height:160px; 
} 
body { 
    margin-left: 0px; 
    margin-top: 0px; 
    margin-right: 0px; 
    background-repeat: no-repeat; 
    background:#000; 
} 

/*----------MENU-----------*/ 


/*main menu*/ 

a:link {color:#fff; text-decoration:none;} 
a:visited {color: #868D65;} 
a:hover {color:#000;} 
a:active {color: #868D65;} 

#navmenu { 
    width:100%; 
    height:80px; 
    margin-right:auto; 
    margin-left:auto; 
} 

/*holds the listed items on main menu*/ 
#navmenu ul { 
    width:100%; 
    margin:0; 
    padding: 0; 
    list-style:none; 
    text-decoration:none; 
} 

/*keeps main menu horiztonal, and effects the actualy list items, overrides any other menu float*/ 
#navmenu li { 
    float:left; 
    padding: 30px 7px; 
    position:relative; 
    list-style:none; 
    text-decoration:none; 
    font-family: Georgia, "Times New Roman", Times, serif; 
    font-size:12px; 
    text-decoration: none; 
    border-top: 2px solid #868D65; 
    border-bottom: 2px solid #868D65; 
    transition: border-radius 1s, background 1s; 
    -moz-transition: -moz-border-radius 1s, background 1s; 
    -webkit-transition: -webkit-border-radius 1s, background 1s; 
    z-index:200; 
} 

/*menu styling for hover, WHEN IMAGE IS ADDED, IT APPLIES TO ALL HOVER ACTIONS ON EVERY MENU*/ 
#navmenu li:hover { 
    background: #eee; 
    background-image: url(style/bgheader.jpg); 
    transition: border-radius 1s, background 1s; 
-moz-transition: -moz-border-radius 1s, background 1s; 
-webkit-transition: -webkit-border-radius 1s, background 1s; 
z-index:200; 
} 
/*SUB MENU STARTS*/ 


/*this hides the submenu*/ 
#navmenu li ul { 
    position: absolute; 
    top:75px; 
    visibility:hidden; 
    padding-left:0px; 
} 
/*this shows the submenu on hover over main menu*/ 
#navmenu li:hover ul {visibility:visible;} 

/*sub menu styling*/ 
#navmenu li ul li { 
    float:none; 
    width: 160px; 
    font-size:12px; 
    text-align:center; 
    padding: 15px 5px 10px 5px; 
    background: #222222; 
    border: 1px solid #FFF; 
    color: #FFF; 
    position:relative; 
    margin-left: -6px; 
} 

/*sub menu styling for hover*/ 
#navmenu li ul li:hover { 
    font-size:12px; 
    color: #000; 
    background-color: #868D65; 
} 
+0

對不起你們,我得到的這個帖子的東西,恆生非常具體的,我的工作就可以了。 – RKMediArt

+0

請直接在代碼中加入代碼。 JSfiddle可以很方便,但不是永久的。通過在其前面放置4個空格(對於塊)來標記代碼,或者通過用反引號圍繞它來內聯代碼。 – KatieK

+0

嗯,沒有最好的運氣在這裏..預覽它會顯示它的鏈接,然後當我認爲我得到它的權利,它不會正確發佈。我道歉。 – RKMediArt

回答

2

Here you go

@media (max-width:600px) { 
    tr td #navmenu li { 
    width:100%; // makes each item takes up the whole screen 
    } 
    tr td #navmenu li ul { 
    position:relative !important; // removes the position absolute so that it doesn't overlap the higher up menu items 
    top:0; // puts it right next to the menu item 
    display:none; // so there is no unnecessary white space when the `li` isn't being hovered over 
    } 
    tr td #navmenu li:hover ul { 
    display:block; // shows the submenu when you hover over the higher `li`s 
    } 
} 
+0

非常感謝您的科迪!我會執行這個!非常感謝! – RKMediArt

+0

@RKMediArt如果此答案對您有幫助,請聯繫Upvote and accept! –

+0

哦,我絕對會!我正在搞亂這個設置,看看它是如何工作的,但是一旦我達到了15的聲望hehe !,非常感謝!簡單的代碼如此強大!, – RKMediArt

1

把這樣的事情在你的手機佈局的媒體查詢

#navmenu li { 
    display: block; 
    text-align: center; 
    float:none; 
} 

#navmenu li ul { 
    display: none; 
    position: relative; 
    top:0; 
    visibility:hidden; 
} 

,因爲你的T關於如何顯示子菜單echnique是純CSS(:對父母和知名度懸停:可見),我們需要JS/jQuery的,因爲我們的孩子菜單顯示:無現

$('li.slidedown').hover(function() { 
    $(this).find('ul').slideDown(); 
}, function() { 
    $(this).find('ul').slideUp(); 
}); 

還沒有檢查了我的代碼,BYT我希望你得到我的點

+0

感謝bondy !,我會看看這個,我將不得不將這添加到我附加的.js文件中,並進行這些css編輯並給它一個鏡頭,非常感謝! – RKMediArt

+0

一旦我檢查了這一點,我會讓你知道它是如何粘結,再次感謝..生病讓你知道,如果我有任何併發​​症。 – RKMediArt

+0

已經過時了,好吧我已經開始工作了,非常感謝你!工作很順利!...你有點擊解決方案嗎?我知道它與觸摸或鼠標事件有關,但是如何在達到特定窗口大小時實現觸摸屏的點擊/點擊 – RKMediArt