【发布时间】:2014-04-13 15:33:49
【问题描述】:
我是 css、html5 和 jquery 的新手。我正在尝试构建一个菜单,其中列表项在悬停时出现和消失。正如 mplungjan 所问的,代码在这里: http://jsfiddle.net/m5ab6/
HTML 是:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link
rel="stylesheet"
href="drop.css"
>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js" ></script>
</head>
<body>
<nav class="main">
<ul id="topbar">
<li class="droplist">Fruits
<ul class="subdrop">
<li>Apple</li>
</ul>
</li>
<li class="droplist">Vegetables
<ul class="subdrop"></ul>
</li>
</ul>
</nav>
</body>
<!-- <script src="drop.js"></script> -->
</html>
CSS 是:-
@CHARSET "UTF-8";
.main{
width: device-width;
height:200px;
}
#topbar
{
background-color: black;
color: grey;
/*display: none;*/
list-style-type: none;
}
.droplist
{
display: inline;
padding: 20px;
position: relative;
}
.subdrop{
display:none;
}
Javascript 是:-
function hoverinfunc(){
$(".subdrop").show(500);
//$("subdrop").css({"position:"})
}
function hoveroutfunc(){
$(".subdrop").hide(500);
}
$(document).ready(
$("li.droplist").hover(hoverinfunc, hoveroutfunc)
);
问题:从水果/蔬菜中悬停会改变蔬菜的布局。通常,蔬菜放在水果的右侧。但是,在水果/蔬菜中不断徘徊会导致蔬菜落入水果之下。我的要求是蔬菜的位置应该总是在水果的右边
我的解决方案(可能是一个幼稚的解决方案):我在 css 文件的 .droplist' 中添加 float:left;。但是,正因为如此,背景颜色丢失了。
请帮助我理解我错在哪里。
【问题讨论】:
-
请添加一个jsfiddle.net
-
并将代码也留在这里!
标签: javascript jquery css html