【问题标题】:MDL-Menu bottom right offscreenMDL-Menu 右下角离屏
【发布时间】:2017-07-02 13:10:05
【问题描述】:

嗨,我正在尝试让以下代码显示在导航栏的右侧,但是当我这样做时,它只显示一半(换句话说,菜单的一半是正确的:-32px;-我没有添加任何 CSS,这是默认的 Material Design lite 代码)。



错误出现在我的 CSS 中 https://codepen.io/russellharrower/pen/RgMJaR

我的核心 getmdl

<link rel="stylesheet" href="https://getmdl.io/assets/components.css">
<script src="https://getmdl.io/assets/components.js"></script>
<script src="//code.getmdl.io/1.3.0/material.min.js"></script>

HTML 代码

            <div class="mdl-layout__header-row">
                <!-- Title -->
                <span class="mdl-layout-title">SITE</span></span>
                <!-- Add spacer, to align navigation to the right -->
                <div class="mdl-layout-spacer"></div>
                <div class="mdl-textfield mdl-js-textfield mdl-textfield--expandable mdl-textfield--floating-label mdl-textfield--align-right">
                    <label class="mdl-button mdl-js-button mdl-button--icon" for="fixed-header-drawer-exp">
                        <i class="material-icons">search</i>
                    </label>
                    <div class="mdl-textfield__expandable-holder">
                        <input class="mdl-textfield__input" type="text" name="sample" id="fixed-header-drawer-exp" />
                    </div>
                </div>

                 <!-- MDL bottom right Aligned Menu Button -->  
             <button id="my-menu-bottom-right"
                    class="mdl-button mdl-js-button mdl-button--icon">
              <i class="material-icons">share</i>
            </button>

            <!-- Menu items List , mdl-menu--bottom-right -->

            <ul class="mdl-menu mdl-menu--bottom-right mdl-js-menu mdl-js-ripple-effect"
                for="my-menu-bottom-right">
              <li class="mdl-menu__item">Facebook</li>
              <li class="mdl-menu__item">Twitter</li>
              <li disabled class="mdl-menu__item">Google Plus</li>
            </ul>

            </div>

        </header> 

这是自动生成的 CSS,我不确定是什么代码生成的或为什么。

element.style {
    right: -35.1563px;
    top: 40px;
    width: 124px;
    height: 160px;
}

错误是

.mdl-textfield{width:100% !important;}

所以我需要设置它的样式,但不要给它一个全局的 .mdl-textfield(否则它会把所有东西都搞砸,所以在那之前 #id of div)

【问题讨论】:

    标签: javascript html css material-design-lite


    【解决方案1】:

    mdl-menu--bottom-leftmdl-menu--bottom-right 在菜单中 ul

    https://codepen.io/anon/pen/wemXBe

    <header class="mdl-layout__header">
    
                <div class="mdl-layout__header-row">
                    <!-- Title -->
                    <span class="mdl-layout-title">SITE</span></span>
                    <!-- Add spacer, to align navigation to the right -->
                    <div class="mdl-layout-spacer"></div>
                    <div class="mdl-textfield mdl-js-textfield mdl-textfield--expandable mdl-textfield--floating-label mdl-textfield--align-right">
                        <label class="mdl-button mdl-js-button mdl-button--icon" for="fixed-header-drawer-exp">
                            <i class="material-icons">search</i>
                        </label>
                        <div class="mdl-textfield__expandable-holder">
                            <input class="mdl-textfield__input" type="text" name="sample" id="fixed-header-drawer-exp" />
                        </div>
                    </div>
    
                     <!-- MDL bottom right Aligned Menu Button -->  
                     <button id="my-menu-bottom-left"
                            class="mdl-button mdl-js-button mdl-button--icon">
                      <i class="material-icons">share</i>
                    </button>
    
                    <!-- Menu items List , mdl-menu--bottom-right -->
                    <!-- mdl-menu--bottom-left to mdl-menu--bottom-right  -->
                    <ul class="mdl-menu mdl-menu--bottom-right mdl-js-menu mdl-js-ripple-effect"
                        for="my-menu-bottom-left">
                      <li class="mdl-menu__item">Facebook</li>
                      <li class="mdl-menu__item">Twitter</li>
                      <li disabled class="mdl-menu__item">Google Plus</li>
                    </ul>
    
                </div>
    
            </header> 
    

    【讨论】:

    • 请解释您更改了什么?因为那不起作用(而且非常不清楚)-注意我使用的是 1.3.0 MDL
    • 一旦您将左侧按钮更改为右侧,您就忘记了更改菜单类。答案已经在您的问题中。
    • 好的,你的代码可以工作 - 我发现错误在我的 CSS 样式 .css 文件中,我将对其进行编码
    • 发现错误 (/*STATUS AREA*/ .status-dialog{width:980px !important;} .mdl-textfield{width:100% !important;})
    猜你喜欢
    • 2017-02-17
    • 2017-09-09
    • 2012-04-02
    • 2019-01-05
    • 2013-02-17
    • 1970-01-01
    • 2018-01-27
    • 2023-03-25
    • 2019-09-04
    相关资源
    最近更新 更多