我发现这很有用:
您可以按照任何响应来简化css代码dropdovn菜单。
添加类parent
对于具有子菜单的项目,添加depth
类别(深度0、深度1、深度2…)添加到函数。php您的主题
class DD_Wolker_Menu extends Walker_Nav_Menu {
function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ){
$GLOBALS[\'dd_children\'] = ( isset($children_elements[$element->ID]) )? 1:0;
$GLOBALS[\'dd_depth\'] = (int) $depth;
parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
}
}
add_filter(\'nav_menu_css_class\',\'add_parent_css\',10,2);
function add_parent_css($classes, $item){
global $dd_depth, $dd_children;
$classes[] = \'depth\'.$dd_depth;
if($dd_children)
$classes[] = \'parent\';
return $classes;
}
现在在页眉中。php
wp_nav_menu( array( \'container_class\' => \'\',\'container\' => \'\', \'menu\' => \'header-menu\', \'walker\'=> new DD_Wolker_Menu ) );
header-menu
替换为菜单名称
CSS示例代码可能是
#menu-header-menu{
margin: 0;
padding: 0;
}
#menu-header-menu ul{
}
#menu-header-menu> li{
display: inline;
margin-left: 1.618em;
}
#menu-header-menu li{
list-style: none;
}
#menu-header-menu li a{
text-decoration: none;
font-size: 1em;
font-family: \'Lato\',Helvetica,Arial,sans-serif ;
letter-spacing: 1px;
}
#menu-header-menu li.parent::after{
content:\'+\';
}
#menu-header-menu .sub-menu {
display: none;
position: absolute;
background-color: #fff;
}
#menu-header-menu li:hover>.sub-menu{
display: inline;
width: auto;
height: auto;
border: solid 1px #BBBBBB;
z-index: +1;
}
在哪里
#menu-header-menu
- id主UL列表(您也需要更新)