【问题标题】:Styles in Drupal menuDrupal 菜单中的样式
【发布时间】:2015-03-02 14:27:43
【问题描述】:

我需要将样式放在 Drupal 菜单中。我有这个代码:

print theme('links', array('links' => menu_navigation_links($menu_area), 'attributes' => array('class'=> array('nav', 'navbar-nav')) ));

    具有“nav navbar-nav”样式,但
  • 具有我无法触摸的自定义 CSS 样式(首先是菜单 7053)。

    有没有办法用打印主题功能改变那个

  • 的样式?

    谢谢。

【问题讨论】:

    标签: css drupal menu drupal-7


    【解决方案1】:

    不,你不能,你需要在你的主题中实现自己的theme_menu_link 函数。

    function YOURTHEME_menu_link(array $variables) {
      $element = $variables['element'];
      $sub_menu = '';
    
      $element['#attributes']['class'][] = 'my-custom-li-class'; // change here to desired css class name
    
      if ($element['#below']) {
        $sub_menu = drupal_render($element['#below']);
      }
    
      $output = l($element['#title'], $element['#href'], $element['#localized_options']);
      return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
    }
    

    【讨论】:

      【解决方案2】:

      您可以使用Menu attributes(https://www.drupal.org/project/menu_attributes) 模块并通过从后端编辑菜单项将类添加到li。请查看下面的截图:

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多