Different mdl-layout__drawer for large screen and

2019-07-09 00:48发布

问题:

I, am trying to create two different mdl-layout__drawer for small screen and large screen. As per the below code only on small screen the mdl-layout__drawer is showing it is not showing on large screen.

<div class="mdl-layout__drawer mdl-layout--large-screen-only">
        <span class="mdl-layout-title"><img src="~/images/transfeteBirdLogo.png" width="80" height="80" /></span>
        <nav class="mdl-navigation">
            <a class="mdl-navigation__link" href="">Link21</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>

    <div class="mdl-layout__drawer mdl-layout--small-screen-only">
        <span class="mdl-layout-title"><img src="~/images/transfeteBirdLogo.png" width="80" height="80" /></span>
        <nav class="mdl-navigation">
            <a class="mdl-navigation__link" href="">Link11</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>

Can anyone tell me what is wrong in the code. How can I solve this issue.

回答1:

Your whole code should be wrapped in a div containing mdl-layout, mdl-js-layout and mdl-layout--fixed-drawer classes. The last one is responsible for showing the navigation menu in large screens. Pen here.

<div class="mdl-layout mdl-js-layout mdl-layout--fixed-drawer">
  <div class="mdl-layout__drawer mdl-layout--large-screen-only">
    <span class="mdl-layout-title"><img src="~/images/transfeteBirdLogo.png" width="80" height="80" /></span>
    <nav class="mdl-navigation">
      <a class="mdl-navigation__link" href="">Link21</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>

  <div class="mdl-layout__drawer mdl-layout--small-screen-only">
    <span class="mdl-layout-title"><img src="~/images/transfeteBirdLogo.png" width="80" height="80" /></span>
    <nav class="mdl-navigation">
      <a class="mdl-navigation__link" href="">Link11</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>
</div>