gpt4 book ai didi

CSS,可以在子菜单上移动 div 吗?

转载 作者:太空宇宙 更新时间:2023-11-03 17:47:06 25 4
gpt4 key购买 nike

所以我有这个下拉菜单。我想知道的是,当有人将鼠标悬停在具有子菜单的菜单项上时,是否可以移动 txt div。这样子菜单就不会显示在 textdiv 上。这是我的代码:http://jsfiddle.net/6koazkhs/ .所以我喜欢的是当有人将鼠标悬停在子菜单上时 txt div 向下 float ,但不是 nav div 正在拉伸(stretch)(颜色方面)的方式。这里有一张图片来解释我想要什么:enter image description here这样的事情可能吗?

这是我的代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test</title>
<style>
body {
font-family: 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, sans-serif;
padding: 20px 50px 150px;
font-size: 13px;
text-align: center;
background: #E3CAA1;
}

ul {
text-align: left;
display: inline;
margin: 0;
padding: 15px 4px 17px 0;
list-style: none;
}
ul li {
font: bold 12px/18px sans-serif;
display: inline-block;
margin-right: -4px;
position: relative;
padding: 15px 20px;
background: #fff;
cursor: pointer;
}
ul li:hover {
background: #555;
color: #fff;
}
ul li ul {
padding: 0;
position: absolute;
top: 48px;
left: 0;
width: 150px;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
display: none;
opacity: 0;
visibility: hidden;
}
ul li ul li {
background: #555;
display: block;
color: #fff;
}
ul li ul li:hover { background: #666; }
ul li:hover ul {
display: block;
opacity: 1;
visibility: visible;
}
div.txt{background:#ddd; width:100%}
div.nav{background:#ccc; width:100%; border-radius:10px;}
</style>

</head>

<body>
<div class="nav"><ul><li>Home</li>
<li>About</li>
<li>
Portfolio
<ul>
<li>Web Design</li>
<li>Web Development</li>
<li>Illustrations</li>
</ul>
</li>
<li>Blog</li>
<li>Contact</li>
</ul></div>
<div class="txt">Here my test</div>
</body>
</html>

最佳答案

不确定您是否可以选择添加额外的 div,但如果您这样做可能会有所帮助

$(".Drop").hover(function(){
$("#Space").slideToggle();
});
body {
font-family: 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, sans-serif;
padding: 20px 50px 150px;
font-size: 13px;
text-align: center;
background: #E3CAA1;
}

ul {
text-align: left;
display: inline;
margin: 0;
padding: 15px 4px 17px 0;
list-style: none;
}
ul li {
font: bold 12px/18px sans-serif;
display: inline-block;
margin-right: -4px;
position: relative;
padding: 15px 20px;
background: #fff;
cursor: pointer;
}
ul li:hover {
background: #555;
color: #fff;
}
ul li ul {
padding: 0;
position: absolute;
top: 48px;
left: 0;
width: 150px;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
display: none;
opacity: 0;
visibility: hidden;
}
ul li ul li {
background: #555;
display: block;
color: #fff;
}
ul li ul li:hover { background: #666; }
ul li:hover ul {
display: block;
opacity: 1;
visibility: visible;
}
div.txt{background:#ddd; width:100%}
div.nav{background:#ccc; width:100%; border-radius:10px;}

#Space{
height:170px;
display:none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="nav"><ul><li>Home</li>
<li>About</li>
<li class="Drop">
Portfolio
<ul>
<li>Web Design</li>
<li>Web Development</li>
<li>Illustrations</li>
</ul>
</li>
<li>Blog</li>
<li>Contact</li>
</ul></div>
<div id="Space"></div>
<div class="txt">Here my test</div>

关于CSS,可以在子菜单上移动 div 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27959567/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com