Material Design Lite Menu not working in Card Design

纵然是瞬间 提交于 2019-12-12 04:40:38

问题


I am using the material design lite to create a menu from the tutorial - https://getmdl.io/components/

here is the code

<div class="mdl-card__actions mdl-card--border">

                        <button id="share-menu" class="mdl-button mdl-button--icon mdl-js-button mdl-js-ripple-effect pull-left">
                            <i class="material-icons">share</i>
                        </button>
                        <ul class="mdl-menu mdl-menu--bottom-left mdl-js-menu mdl-js-ripple-effect"
                            for="share-menu">
                            <li class="mdl-menu__item">Some Action</li>
                            <li class="mdl-menu__item mdl-menu__item--full-bleed-divider">Another Action</li>
                            <li disabled class="mdl-menu__item">Disabled Action</li>
                            <li class="mdl-menu__item">Yet Another Action</li>
                        </ul>
                        <span class="mdl-chip mdl-chip--contact center-block">
                            <span class="mdl-chip__contact mdl-color--teal mdl-color-text--white">12</span>
                            <button class="mdl-button mdl-button--icon mdl-button--colored"><i class="material-icons">thumb_up</i></button>
                        </span>
                        <button class="mdl-button mdl-button--icon mdl-button--colored pull-right"><i class="material-icons">add_shopping_cart</i></button>
                    </div>

When click on the share button the menu is not created here is the image of the design


回答1:


Replacing the 'for' attribute of the 'ul' element to 'data-mdl-for' should fix the problem.

Try the below code

<div class="mdl-card__actions mdl-card--border">

                    <button id="share-menu" class="mdl-button mdl-button--icon mdl-js-button mdl-js-ripple-effect pull-left">
                        <i class="material-icons">share</i>
                    </button>
                    <ul class="mdl-menu mdl-menu--bottom-left mdl-js-menu mdl-js-ripple-effect"
                        data-mdl-for="share-menu">
                        <li class="mdl-menu__item">Some Action</li>
                        <li class="mdl-menu__item mdl-menu__item--full-bleed-divider">Another Action</li>
                        <li disabled class="mdl-menu__item">Disabled Action</li>
                        <li class="mdl-menu__item">Yet Another Action</li>
                    </ul>
                    <span class="mdl-chip mdl-chip--contact center-block">
                        <span class="mdl-chip__contact mdl-color--teal mdl-color-text--white">12</span>
                        <button class="mdl-button mdl-button--icon mdl-button--colored"><i class="material-icons">thumb_up</i></button>
                    </span>
                    <button class="mdl-button mdl-button--icon mdl-button--colored pull-right"><i class="material-icons">add_shopping_cart</i></button>
                </div>

Hope this helps



来源:https://stackoverflow.com/questions/45156921/material-design-lite-menu-not-working-in-card-design

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!