如何将背景图像添加到离子侧菜单

How to add background image to ionic side menu

我有一个离子侧边菜单。我想添加背景图像。侧边菜单代码如下。

<ion-side-menus enable-menu-with-back-views="true">
<ion-side-menu-content>
    <ion-nav-bar class="bar-dark">
        <ion-nav-back-button>
        </ion-nav-back-button>      
        <ion-nav-buttons side="left">
            <button class="button button-icon button-clear ion-navicon" menu-toggle="left"></button>
        </ion-nav-buttons>
        <ion-nav-buttons side="right">
            <button  class="button button-icon button-clear ion-log-out" ng-click="logout()"></button>
        </ion-nav-buttons>          
    </ion-nav-bar>
    <ion-nav-view name="menuContent" style="background-color:red;">   
    </ion-nav-view>
</ion-side-menu-content>
    <ion-side-menu side="left">
        <ion-header-bar class="bar-dark">
            <h1 class="title">Menu</h1>
        </ion-header-bar>
        <ion-content>
            <ion-list>
                <ion-item menu-close href="#/app/dashboard">
                    <i class="icon icon-dashboard" style="font-size:20px;margin-right:10px;"></i>
                    Dashboard
                </ion-item> 
<ion-item menu-close href="#/app/dashboard">
                    <i class="icon icon-dashboard" style="font-size:20px;margin-right:10px;"></i>
                    Statistics
                </ion-item>             
            </ion-list>
        </ion-content>
    </ion-side-menu>
</ion-side-menus>

如何给 ionic 侧边菜单添加背景图片?

您可以按如下方式定义您的自定义 CSS:

.my-container {
    background-image:  url("http://www.planwallpaper.com/static/images/colorful-triangles-background_yB0qTG6.jpg");
    background-repeat: repeat;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    background-size: cover;
    height: 100%;
    position: absolute;
}
.transp .item-content {
    background-color: transparent !important;
    color: #fff;
}

并将这些 类 应用于适当的 HTML 项目:

<ion-side-menu side="left">
    <ion-header-bar class="bar-dark">
        <h1 class="title">Menu</h1>
    </ion-header-bar>
    <ion-content class="my-container">
        <ion-list>
            <ion-item class="transp" menu-close href="#/app/dashboard">
                <i class="icon icon-dashboard" style="font-size:20px;margin-right:10px;"></i>Dashboard
            </ion-item> 
            <ion-item class="transp" menu-close href="#/app/dashboard">
                <i class="icon icon-dashboard" style="font-size:20px;margin-right:10px;"></i>Statistics
            </ion-item>             
        </ion-list>
    </ion-content>
</ion-side-menu>

这是一个代码笔:http://codepen.io/beaver71/pen/WrqgNm

好吧,我不确定这是否是正确的方法,但您可以在 <ion-content> </ion-content>

中试试这个
<ion-content style="background: url('img/a.jpg'); background-size: cover;">
    <ion-list>
        <ion-item menu-close href="#/app/dashboard">
            <i class="icon icon-dashboard" style="font-size:20px;margin-right:10px;"></i>
                Dashboard
        </ion-item> 
        <ion-item menu-close href="#/app/dashboard">
            <i class="icon icon-dashboard" style="font-size:20px;margin-right:10px;"></i>
                Statistics
        </ion-item>             
   </ion-list>
</ion-content>

这可能对您的案子有所帮助。