我面對困難,使下拉列表看起來不錯,因爲它已經搞砸了與CSSCSS邊距和填充問題
DEMO.HTML:
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="demo.css">
<style>
li{
display: block;
}
</style>
</head>
<body>
<div id='wrap'>
<div id="clickable_div">MENU</div>
<div id="nav_menu">
<ul class="dropDown">
<li id="li_1"><img src="images/ori_12.png"></li>
<li id="li_2"><img src="images/ori_14.png"></li>
<li id="li_3"><img src="images/ori_15.png"></li>
<li id="li_4"><img src="images/ori_16.png"></li>
</ul>
</div>
</div>
</div>
</body>
<script>
$('#wrap').mouseover(function(){
$('#nav_menu').slideDown();
});
$('#wrap').mouseleave(function(){
$('#nav_menu').slideUp();
});
$('#nav_menu li img')
.mouseover(function() {
this.src = this.src.replace('/ori_', '/hover_');
})
.mouseout(function() {
this.src = this.src.replace('/hover_', '/ori_');
});
</script>
</html>
DEMO.CSS:
#clickable_div {
width: 166px;
background-color: #9c9c9c;
display: block;
}
#nav_menu {
width: 166px;
height: auto;
background-color: #CCC;
display: none
}
//*{padding:0;margin:0} This will achieve what I want but eventually all my other elements on the same page will have no padding and margin
#wrap {
width: 166px;
}
通過複製代碼,您將看到下拉菜單已混亂。它可以通過使用*{padding:0;margin:0}
來修復,但同一頁面上的所有其他元素將沒有填充和邊距,這絕對不是所需的輸出。我已經嘗試設置填充和邊距爲0的每個元素,例如#wrap
,#nav_menu
但它們都不起作用。
嗨PSL,請幫忙看看我的另一個問題@ http://stackoverflow.com/questions/19019122/weird-behaviour-of-css-dropdown-menu感謝您的幫助! –
@IsaacLem發佈了一個答案。 – PSL