我发现这很有用:
您可以按照任何响应来简化CSS代码dropdovn菜单。
parent
为具有子菜单的项目添加类
- 添加
depth
类(depth0,depth1,depth2 ...)
添加到function.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;
}
现在在header.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
-标识主要的UL列表(您也需要对其进行更新)