gpt4 book ai didi

CSS 菜单问题 : Submenu appears active when parent menu item is active (current) page

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

我好迷茫!这是我正在开发的网站:Cancer Support site

我似乎有两个问题...我花了很多时间试图找出解决方案...所以我真的希望有人能提供帮助。

问题 1:如果显示的是当前页面,我使用 ID=navactive 来保持父菜单项处于事件状态。这样可行。但是,我对 CSS 进行编码的方式引入了一个错误,即当子菜单项首次出现在 ID=navactive 父级的鼠标悬停时,它们会显示为事件状态。相反,子菜单项最初应该显示为非事件状态,直到它们实际被鼠标悬停。在站点上,您可以看到“主页”页面是父菜单上的事件页面。如果将鼠标悬停在它上面,会出现两个子子菜单……但它们显示为事件状态。它们应该显示为非事件状态 - 与将鼠标悬停在“我们的工作”父菜单项上时子菜单的显示方式相同。

问题 2:我的孙子菜单项都没有出现。在“主页”和“我们的工作”父菜单项下,我有以下配置:

Top level menu (parent)
Submenu 1 (child 1)
Submenu 2 (grandchild 1)
Submenu 3 (child 2)

相反,它出现在这样的页面上,其中孙子 1 变成了子 2,并且没有孙子可见(并且缺少原始子 2 [子菜单 3]):

Top level menu (parent)
Submenu 1 (child 1)
Submenu 2 (child 2)

如有任何建议,我们将不胜感激!!!谢谢!

为了您的方便..这是我的导航菜单部分的CSS代码:

#navcontainer 
{
width: 711px;
height: 25px;
text-align: center;
margin: 0px auto; /*Center container on page*/
clear: both;
background-color: #129F9F;
border: 3px solid #FFFFFF;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
-o-border-radius: 5px;
-ms-border-radius: 5px;
border-radius: 5px;

/* IE10 Consumer Preview */
background-image: -ms-linear-gradient(top, #16ACAC 0%, #0D6F6F 100%);

/* Mozilla Firefox */
background-image: -moz-linear-gradient(top, #16ACAC 0%, #0D6F6F 100%);

/* Opera */
background-image: -o-linear-gradient(top, #16ACAC 0%, #0D6F6F 100%);

/* Webkit (Safari/Chrome 10) */
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, #16ACAC), color-stop(1, #0D6F6F));

/* Webkit (Chrome 11+) */
background-image: -webkit-linear-gradient(top, #16ACAC 0%, #0D6F6F 100%);

/* W3C Markup, IE10 Release Preview */
background-image: linear-gradient(to bottom, #16ACAC 0%, #0D6F6F 100%);
}
.main_menu
{
height: 24px;
line-height: 24px;
font-size: 12px;
position: relative;
}
.main_menu ul
{
padding: 0px 0px 0px 35px; /* padding on left to get nav menu to center.. since it has a float left to make it display properly*/
list-style: none;
}
.main_menu ul li
{
padding: 0;
margin: 0;
border-right: 2px solid #129F9F;
float: left;
}
.main_menu ul li.navcontact /* to stop right border at end of nav line */
{
padding: 0;
margin: 0;
border-right: none;
float: left;
}
.main_menu ul li a
{
color: #FFF;
display: block;
text-decoration: none;
padding: 0 15px;
}
.main_menu ul > li:hover > a, #navactive a:link, #navactive a:visited, #navactive > ul > li > a:hover
{
text-decoration: none;
color: #EAA339;
/* IE10 Consumer Preview */
background-image: -ms-linear-gradient(top, #0D6F6F 0%, #16ACAC 100%);

/* Mozilla Firefox */
background-image: -moz-linear-gradient(top, #0D6F6F 0%, #16ACAC 100%);

/* Opera */
background-image: -o-linear-gradient(top, #0D6F6F 0%, #16ACAC 100%);

/* Webkit (Safari/Chrome 10) */
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, #0D6F6F), color-stop(1, #16ACAC));

/* Webkit (Chrome 11+) */
background-image: -webkit-linear-gradient(top, #0D6F6F 0%, #16ACAC 100%);

/* W3C Markup, IE10 Release Preview */
background-image: linear-gradient(to bottom, #0D6F6F 0%, #16ACAC 100%);
}
.main_menu ul li ul
{
display: none;
width: auto;
position: absolute;
padding: 0px;
margin: 0px;
}
.main_menu ul li:hover ul
{
display: block;
position: absolute;
margin: 0;
padding: 0;
}
.main_menu ul li:hover li
{
float: none;
list-style: none;
margin: 0px;
}
.main_menu ul li:hover li
{
font-size: 12px;
height: 24px;
background: #54C4C4;
/* border-top: 1px solid #129F9F; */
border: 1px solid #FFFFFF;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
-o-border-radius: 5px;
-ms-border-radius: 5px;
border-radius: 5px;
}
.main_menu ul li:hover li a
{
font-size: 11px;
color: #fff;
padding: 0px;
display: block;
width: 150px;
}
.main_menu ul li li a:hover
{
font-size: 11px;
height: 24px;
color:#EAA339;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
-o-border-radius: 5px;
-ms-border-radius: 5px;
border-radius: 5px;
}

这是 HTML 代码:

    <div id="navcontainer">
<div class="main_menu">
<ul>
<li id="navactive"><a href="index.asp" title="Cancer Support for Families Foundation is a community funded, community focused cancer charity.">Home</a>
<ul>
<li><a href="CSFF_presentation.pdf" title="Presentation about CSS in PDF format">submenu 1</a>
<ul>
<li><a href="CSFF_presentation.pdf" title="Presentation about CSS in PDF format">submenu 2</a></li>
</ul>
</li>
<li><a href="CSFF_presentation.pdf" title="Presentation about CSS in PDF format">submenu 3</a></li>
</ul>
</li>
<li><a href="what_is_csff.asp" title="Supporting families in financial need who are living with cancer.">What is CSFF</a>
<ul>
<li><a href="CSFF_presentation.pdf" title="Presentation about CSS in PDF format">submenu 4</a></li>
</ul>
</li>
<li><a href="make_a_donation.asp" title="CSFF supporters can fund the charitable support programs, community experiences and fundraising events.">Make a Donation</a></li>
<li><a href="our_work.asp" title="Individuals and families battling cancer need more financial support. CSFF can help.">Our Work</a>
<ul>
<li><a href="CSFF_presentation.pdf" title="Presentation about CSS in PDF format">submenu 5</a>
<ul>
<li><a href="CSFF_presentation.pdf" title="Presentation about CSS in PDF format">submenu 6</a></li>
</ul>
</li>
<li><a href="CSFF_presentation.pdf" title="Presentation about CSS in PDF format">submenu 7</a></li>
</ul>
</li>
<li><a href="our_events.asp" title="Local communities come together in a relaxed family friendly environment to support those living with cancer.">Events Outline</a></li>
<li class="navcontact"><a href="contact_csff.asp" title="Contact CSFF to help those in need.">Contact Us</a></li>
</ul>
</div>
</div>

最佳答案

您遇到此问题的原因是您的 CSS 和您构建 HTML 代码的方式。这是你的问题 -

.main_menu ul > li:hover > a, #navactive a:link, #navactive a:visited, #navactive > ul > li > a:hover 
{
STYLES
}

只需将上面 CSS 代码的“#navactive a:link”部分更改为处理事件链接的单独类。目前,“navactive”div 中的任何链接都将继承此类中给出的样式,这就是子菜单文本显示为黄色而不是白色的原因。所以就像我说的将上面的 CSS 代码更改为一个单独的类,例如 - “#navactive .current”

然后将您的 HTML 代码更改为如下所示:

<div id="navcontainer">
<div class="main_menu">
<ul>
<li id="navactive"><a class="current" href="index.asp" title="Cancer Support for
Families Foundation is a community funded, community focused cancer charity.">Home</a>

这应该可以解决问题!显然我无法对其进行测试,但如果您有任何问题,请告诉我。也只是一个提示 - 当遇到这类问题时,使用 Chrome 的“检查元素”功能非常有用!

关于CSS 菜单问题 : Submenu appears active when parent menu item is active (current) page,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14310083/

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