android - CSS“背景尺寸:封面”不适用于Android设备
问题描述
我正在使用 Ionic 4 Angular 应用程序并设置样式<ion-slide>
以显示背景。
我background-size: cover;
在 CSS 中使用。在浏览器和 iOS 设备上一切看起来都很完美,但在 Android 设备上运行时,背景显示不正确。我在下面附上了一些截图供参考。
HTML:
<ion-slide class="step-two">
<div class="slide-container">
<h1>Find</h1>
<p>Tap into stockists and discover where to buy your favourite beers.</p>
<ion-img class="swipe-img" src="../../assets/imgs/swipe.svg"></ion-img>
</div>
</ion-slide>
CSS:
.step-two {
background: linear-gradient(rgba(121, 168, 226, .9), rgba(0, 0, 0, .7)), url("../../assets/imgs/onboarding-bg2.jpg") no-repeat center;
background-size: cover;
color: var(--ion-color-primary-contrast);
}
.slide-container {
width: 80%;
}
在 iOS 设备上正确显示:
在 Android 设备上显示不正确:
我试图在幻灯片上设置一个高度,如下所示:
.step-two {
background: linear-gradient(rgba(121, 168, 226, .9), rgba(0, 0, 0, .7)), url("../../assets/imgs/onboarding-bg2.jpg") no-repeat center;
background-size: cover;
color: var(--ion-color-primary-contrast);
height: 100%; // This didn't work. The height was less than the view height of the device (about 30% in fact). Also tried 100vh which filled the view height but didn't fix the cover issue.
}
除了封面尺寸不正确外,背景图片似乎也没有以 Android 为中心。
非常感谢任何帮助。谢谢。
解决方案
尝试使用“100% 100%”而不是使用背景大小作为“封面”。它将根据容器设置图像的 100% 宽度和 100% 高度。像这样:
background-size:100% 100%;
例子:
.step-two {
background: linear-gradient(rgba(121, 168, 226, .9), rgba(0, 0, 0, .7)), url("../../assets/imgs/onboarding-bg2.jpg") no-repeat center;
background-size: 100% 100%;
color: var(--ion-color-primary-contrast);
height: 100%;
}
推荐阅读
- xml - 我如何在 xslt 1.0 / xml 中使用 else 函数
- javascript - Javascript中.sort()方法的问题,两个数组排序而不是一个
- java - Selenium try/catch click 似乎需要很长时间?
- python - 在 Folium html 文件中嵌入浮动图像
- kubernetes - 在 Helm 3 中将代理设置为环境变量
- asp.net - Razor .resx 视图本地化
- algorithm - 寻找有效的区间树算法
- c# - 使用 XUnit 测试内部方法引发空引用异常
- android - 使用 MaterialComponents 和 BottomNavigationView 的奇怪行为。安卓
- mongodb - 无法再连接到 mongoDB Atlas