想在Material Design Lite中的右上角显示菜单图标按钮。

5

我想将菜单图标按钮移到页面右上角,但它出现在标题下方。我应该添加哪种属性或属性值?

    <!-- Simple header with fixed tabs. -->
<div class="mdl-layout mdl-js-layout mdl-layout--fixed-header
            mdl-layout--fixed-tabs">
  <header class="mdl-layout__header">
    <div class="mdl-layout__header-row">
      <!-- Title -->
      <span class="mdl-layout-title">Title</span>
    </div>
    <!-- Right aligned menu below button -->

<button id="demo-menu-lower-right"
        class="mdl-button mdl-js-button mdl-button--icon">
  <i class="material-icons">more_vert</i>
</button>

<ul class="mdl-menu mdl-menu--bottom-right mdl-js-menu mdl-js-ripple-effect"
    for="demo-menu-lower-right">
  <li class="mdl-menu__item">Some Action</li>
  <li class="mdl-menu__item">Another Action</li>
  <li disabled class="mdl-menu__item">Disabled Action</li>
  <li class="mdl-menu__item">Yet Another Action</li>
</ul>
    <!-- Tabs -->
    <div class="mdl-layout__tab-bar mdl-js-ripple-effect">
      <a href="#fixed-tab-1" class="mdl-layout__tab is-active">Tab 1</a>
      <a href="#fixed-tab-2" class="mdl-layout__tab">Tab 2</a>
      <a href="#fixed-tab-3" class="mdl-layout__tab">Tab 3</a>
      <a href="#fixed-tab-4" class="mdl-layout__tab">Tab 4</a>
    </div>
  </header>

here is a image url


你能提供你的 CSS 代码吗? - Amit singh
你可以使用CSS的position: absolute属性将菜单图标按钮定位在右上角。 - vivekkupadhyay
@Amitsingh 这与 CSS 代码无关。 - Anvar Erkinov
2个回答

1
  <div class="mdl-layout mdl-js-layout mdl-layout--fixed-header
        mdl-layout--fixed-tabs">
       <header class="mdl-layout__header">
          <div class="mdl-layout__header-row">
              <div class="row" style="margin:0">
                 <!-- Title -->
                  <span class="mdl-layout-title left">Title</span>

                 <!-- Right aligned menu below button -->

                 <button id="demo-menu-lower-right" class="mdl-button mdl-js-button mdl-button--icon right">
                   <i class="material-icons">more_vert</i>
                 </button>
               </div>
           </div>
           <ul class="mdl-menu mdl-menu--bottom-right mdl-js-menu mdl-js-ripple-effect" for="demo-menu-lower-right">
              <li class="mdl-menu__item">Some Action</li>
                 <li class="mdl-menu__item">Another Action</li>
               <li disabled class="mdl-menu__item">Disabled Action</li>
              <li class="mdl-menu__item">Yet Another Action</li>
           </ul>
            <!-- Tabs -->
             <div class="mdl-layout__tab-bar mdl-js-ripple-effect">
              <a href="#fixed-tab-1" class="mdl-layout__tab is-active">Tab 1</a>
              <a href="#fixed-tab-2" class="mdl-layout__tab">Tab 2</a>
               <a href="#fixed-tab-3" class="mdl-layout__tab">Tab 3</a>
              <a href="#fixed-tab-4" class="mdl-layout__tab">Tab 4</a>
              </div>
            </header>

我已经编辑了你提供的代码。希望这能有所帮助。

谢谢您的回复。但是您的代码没有正常运行,请参考:http://pix.sevelina.ru/images/2015/08/28/12.jpg - Anvar Erkinov
是的,你是正确的。但是你可以通过将左侧和右侧类应用到元素来对齐左侧/右侧元素。更多帮助请参考此链接:http://materializecss.com/helpers.html - chandni

1
为了让菜单出现在右侧,您需要在mdl-layout__header-row元素内添加以下div,然后添加您所需的任何元素到头部的右侧。请参考Material Design Lite中布局的更多细节。
<div class="mdl-layout mdl-js-layout">
  <header class="mdl-layout__header mdl-layout__header--transparent">
    <div class="mdl-layout__header-row">
      <!-- Title -->
      <span class="mdl-layout-title">Title</span>

      <!-- Add spacer, to align navigation to the right -->
      <div class="mdl-layout-spacer"></div>

      <!-- Navigation -->
      <nav class="mdl-navigation">
        <a class="mdl-navigation__link" href="">Link</a>
        <a class="mdl-navigation__link" href="">Link</a>
        <a class="mdl-navigation__link" href="">Link</a>
        <a class="mdl-navigation__link" href="">Link</a>
      </nav>

      <!-- Right Menu -->
      <button id="demo-menu-lower-right"
              class="mdl-button mdl-js-button mdl-button--icon">
        <i class="material-icons">more_vert</i>
      </button>

      <ul class="mdl-menu mdl-menu--bottom-right mdl-js-menu mdl-js-ripple-effect"
          for="demo-menu-lower-right">
        <li class="mdl-menu__item">Some Action</li>
        <li class="mdl-menu__item">Another Action</li>
        <li disabled class="mdl-menu__item">Disabled Action</li>
        <li class="mdl-menu__item">Yet Another Action</li>
      </ul><!--/Right Menu -->
    </div>
  </header>
  <div class="mdl-layout__drawer">
    <span class="mdl-layout-title">Title</span>
    <nav class="mdl-navigation">
      <a class="mdl-navigation__link" href="">Link</a>
      <a class="mdl-navigation__link" href="">Link</a>
      <a class="mdl-navigation__link" href="">Link</a>
      <a class="mdl-navigation__link" href="">Link</a>
    </nav>
  </div>
  <main class="mdl-layout__content">
  </main>
</div>

此外,如果您想更改菜单的位置,可以将 mdl-menu--bottom-right 更改为您喜欢的方向。请参考页面底部的 MDL 菜单 规格。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接