首页 > 解决方案 > Ionic4:将图像大小作为背景图像 url 的封面

问题描述

由于图像太大,我想将背景图像提供给 ion-toolbar,因此我想将其image-size: cover用于背景图像,以使其最适合 ion-toolbar。

我试图以下面的格式给出,但它没有用,不知道如何让它工作。

ion-toolbar {
    --background: url(assets/images/background/bg-header-flag.jpg) no-repeat cover;
    --min-height: 200px;
}

标签: angularionic-frameworkionic4

解决方案


挣扎了这么久终于得到了答案

    --background: url('assets/images/background/bg-header-flag.jpg') center/ cover no-repeat;

下面是使用背景属性简写的语法。

background: bg-color bg-image position/bg-size bg-repeat bg-origin bg-clip bg-attachment initial|inherit;

有关更多详细信息,请查看https://www.w3schools.com/cssref/css3_pr_background.asp


推荐阅读