matdev
March 24, 2015, 5:20pm
1
I am currently using the following CSS
.home-background {
background: url("images/phone/home.png") no-repeat fixed center;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
}
with my home view:
<ion-view view-title="Home" class="home-background">...</ion-view>
This results in the background image being zoomed on, with large parts missing on sides, top and bottom.
Is it a bug ?
Can ionic scale the image automatically so that the full width of the image is displayed (or full heigth) ?
instead of background-size: cover; try background-size: 100%;
matdev
March 24, 2015, 5:43pm
3
same problem with background-size: 100%;
Hmm strange. Cover is equivalent of 100% 100%; so it will crop both sides while trying to scale it proportionly. But setting it to 100% should theoretically only crop one side (vertical)
matdev
March 25, 2015, 10:54am
5
Strange indeed, because the full width of the image appears on the emulator.
It’s only on the galaxy S3 device that image sides are cropped
Ah maybe background-size is not supported on old webkit engine that comes with old android? Maybe you need crosswalk
Yeah, seems that older android has some partial support for background-image options.
http://caniuse.com/#feat=background-img-opts
soone
June 9, 2015, 6:43am
8
hi,now have you find a solution to the problem??
matdev
June 9, 2015, 12:52pm
9
I use background-size: contain;
Using background-size: cover;
doesn’t yield the results described in http://www.w3schools.com/cssref/css3_pr_background-size.asp
jonas
June 9, 2015, 2:16pm
10
Instead, try to set the background on the <ion-content>
element:
<ion-view>
<ion-content class="home-background">...</ion-content>
</ion-view>
and CSS:
.home-background {
background: url(images/phone/home.png) no-repeat center center fixed;
background-size: cover;
}
Note! Is your home.png
showing at all? Make sure you make an absolute path from the .css
file. I usually have to do something like: url(../images/.....
, but that might be dependent on how you set up your project.
7 Likes
janptr
October 28, 2017, 1:39pm
12
thank you! that’s perfect!
{
background: white;
display: block;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: 1;
opacity: 1;
background-size: 100% 100%;
background-position: center;
background: url("…/assets/imgs/registration_bg_v1.png");
background-repeat: no-repeat;
-ms-background-size: cover;
-o-background-size: cover;
-moz-background-size: cover;
-webkit-background-size: cover; // background-position: 53% 89%;
-ms-background-size: cover;
// background-size: cover;
background-position-y: 90%;
}
set this to ion-content will also work… thanks for sharing …
This code works for me
ion-content{
--background: url('../your/path/image.png') no-repeat cover fixed center;
background: url('../your/path/image.png') no-repeat fixed center;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
}
3 Likes
txmge
August 29, 2020, 4:57pm
15
Your code works but only because the “–background” statement is no valid css. I found this solution to work the best:
ion-toolbar {
--background: none;
background: url("../assets/img/gradient.png") no-repeat fixed center;
background-size: cover;
}
1 Like
This solved a problem of mine too!!! thank you very very much!