我有一个三级层次的superfish垂直菜单。
Level-1 Level-2 Level-3
Fruit Apples Green链接文本颜色为白色背景上的红色。当我向下悬停到第三级项目(绿色)时,菜单展开时,我希望活动路径(顶部、中间和底部选定的路径级别)在红色背景上反转为白色文本。翻转选定的链接(绿色)很容易使用:hover,不知何故在苹果和水果的背景翻转,但文本仍然是红色的,不再可读。如何选择水果和苹果来控制其文本颜色?
附加信息:这是superfish的drupal实现,但我认为这无关紧要。css由以下内容定义
a {color:red; background-color:white;}并在下面说明悬停条件
.sf-menu li:active, /* no effect from this line*/
.sf-menu li:hover,
.sf-menu li:focus,/* no effect from this line*/
.sf-menu li.sfHover,
.sf-menu li:active a,
.sf-menu a:focus,
.sf-menu a:hover,
.sf-menu a:active {
background: red; /*Hover background */
color: white;
}还有Superfly注入的其他类和设置,可以修改边距,但不同条件的填充和位置设置,但没有寻址颜色。据我所知,当用户将鼠标悬停在某个项目上时,superfly菜单使用js来显示隐藏的菜单部分。但我不能确定当我将鼠标悬停在苹果或绿色上时,它是如何保持水果背景为红色的,而不是改变文本的颜色。
下面是一个用于菜单显示的实际html级联
<ul id="superfish-3" class="menu sf-menu sf-menu-materials sf-vertical sf-style-MatMenu2 sf-total-items-23 sf-parent-items-22 sf-single-items-1 superfish-processed sf-js-enabled sf-shadow">
<li id="menu-899-3" class="first odd sf-item-1 sf-depth-1 sf-no-children">
<li id="menu-900-3" class="middle even sf-item-2 sf-depth-1 sf-total-children-8 sf-parent-children-0 sf-single-children-8 menuparent">
<a class="sf-depth-1 menuparent sf-with-ul" title="FRUIT" href="/specs/03">
FRUIT
<span class="sf-sub-indicator"> »</span>
</a>
<ul style="display: none; visibility: hidden; float: none; width: 12em;">
<li id="menu-901-3" class="first odd sf-item-1 sf-depth-2 sf-no-children" style="white-space: normal; float: left; width: 100%;">
<a class="sf-depth-2 " title="**APPLE**" href="/specs/031000" style="float: none; width: auto;">APPLE</a>
</li>如您所见,定义了许多类。就像我说的,我搞不懂为什么悬停背景颜色仍然适用于父级,而文本颜色又回到了非悬停显示。我只是想找到一个类,这个类可以选择悬停项的父项,并将文本保持在悬停状态(白色)。
发布于 2012-03-16 03:19:45
你有链接到你的网站吗?
作为开箱即用的猜测,请尝试:
/* 3rd level links, no hover */
.sf-menu li li li a, .sf-menu li.sfHover li li a {
color: white;
}
/* 3rd level links, hover */
.sf-menu li li li a:hover, .sf-menu li.sfHover li li a:hover {
color: white;
background-color: red;
}为此整理样式可能会很棘手,但我发现使用它可以有所帮助。它用丑陋的颜色设计菜单样式,但给了你一个很好的机会去掌握CSS。让我知道你的进展:
编辑:此选项适用于水平菜单:
/*** COLOR SKIN ***/
/* main ul element */
.sf-menu {
border-right: 1px solid FUCHSIA;
float:left;
}
/* general link styles*/
.sf-menu a {
display: block;
padding:9px 13px;
text-decoration:none;
border-top: 1px solid;
border-left: 1px solid;
border-bottom: 1px solid;
}
/*** 1st Level ***/
/* 1st level links, no hover, no visits */
.sf-menu li a {
color: yellow;
background-color: green;
border-color: red;
}
/* 1st level links, while hovering over sub menu */
.sf-menu li.sfHover a{
color: black;
background-color: silver;
}
/* 1st level links, hover */
.sf-menu li a:hover {
color: white;
background-color: lime;
}
/* 1st level current page */
.sf-menu .current_page_item a,
.sf-menu .current_page_ancestor a,
.sf-menu .current_page_parent a {
border-bottom-color: white;
background-color: TEAL;
}
/* 1st level down triangles with pure css*/
.sf-menu li .sf-sub-indicator {
text-indent:-9999px;
line-height: 0;
border-color:YELLOW transparent transparent;
border-style:solid;
border-width:4px; /*controls size of triangle */
display:inline-block;
margin-left:5px;
}
/*** 2nd level ***/
/* sub menu */
.sf-menu ul {
border-right:1px solid;
border-bottom:1px solid;
border-color: yellow;
}
.sf-menu li:hover ul,
.sf-menu li.sfHover ul {
top:32px; /* overriding essential styles- adjust if you have gaps between first level and drop-down sub menu*/
}
.sf-menu ul ul {
margin-top:0; /*unlikely to need adjusting */
}
/* 2nd level links, no hover */
.sf-menu li li a, .sf-menu li.sfHover li a {
color: orange;
background-color: blue;
border-color: green;
border-bottom: 0;
}
/* 2nd level links, while hovering over sub menu */
.sf-menu li li.sfHover a{
color: black;
background-color: silver;
}
/* 2nd level links, hover */
.sf-menu li li a:hover, .sf-menu li.sfHover li a:hover {
color: white;
background-color: aqua;
}
/* 2nd level current page */
.sf-menu li li.current_page_item a,
.sf-menu li li.current_page_ancestor a,
.sf-menu li li.current_page_parent a {
background-color: TEAL;
}
/* 2nd level side triangles with pure CSS */
.sf-menu li li .sf-sub-indicator { /*right arrow*/
border-color: transparent transparent transparent WHITE;
}
/*** 3rd Level and beyond ***/
/* 3rd level links, no hover */
.sf-menu li li li a, .sf-menu li.sfHover li li a {
color: blue;
background-color: red;
border-color: blue;
}
/* 3rd level links, hover */
.sf-menu li li li a:hover, .sf-menu li.sfHover li li a:hover {
color: white;
background-color: pink;
}
/* 2nd level current page */
.sf-menu li li li.current_page_item a,
.sf-menu li li li.current_page_ancestor a,
.sf-menu li li li.current_page_parent a {
background-color: TEAL;
}https://stackoverflow.com/questions/9059642
复制相似问题