I want to create app in Nativescript with fullscreen image on page. I have to use background-image: url('~/images/background.jpg');. But how to make it full screen.
Thanks for your help
You need to use the NativeScript supported CSS properties to achieve this.
I've used the following CSS on a background-image attached to the <Page> view before and it works fine.
.coverImage {
background-image: url('~/images/kiss.jpg');
background-repeat: no-repeat;
background-position: center;
background-size: cover;
}
If you want the Page to have a fullscreen image background, add your images to /App_Resources and do this in your component:
export class MyComponent implements OnInit {
constructor(private page:Page) {}
ngOnInit() {
this.page.actionBarHidden = true;
this.page.backgroundImage = "res://bg-image";
}
}
Update: You can add CSS to enforce fullscreen.
.page {
/* background-image: url("res://bg-image") */
background-size: cover;
background-repeat: no-repeat;
/* background-attachment: fixed; */ /* not supported in {N} yet */
background-position: center top; /* instead set ypos to top to avoid scroll-up */
}
Note: Assign this CSS class to your Page.
if you're using nativeScipt with Angular, you can use:
/*In your .css: */
.my-class {
background-image: url("res://image-name.png") no-repeat;
}
<!-- in your .html: -->
<ScrollView class="my-class">
This does not work with animated gif.
My style:
.page{
background-image: url("~/assets/images/animated.gif") black;
background-repeat: no-repeat;
background-position: center;
background-size: cover;
}
The gif is shown, centered and enlarged, so great, but static: the animation does not moves.
This worked for me:
constructor(private page: Page) { }
ngOnInit() {
this.page.actionBarHidden=true;`
this.page.backgroundImage = 'res://gold_bg';
this.page.style.backgroundSize='cover';
this.page.style.backgroundRepeat='no-repeat';
}
I had a very large image, where the background-size: cover; did not show the image well neither in landscape ( squeezed and narrow ) /portrait ( goes out of the page )
Eventually what worked best for me was to add an Image element, and set it as background
<Image src="~/assets/images/background.jpg" stretch="aspectFill" left="0" top="0" width="100%" height="100%"></Image>
<AbsoluteLayout>
<Image src="~/assets/images/background.jpg" stretch="aspectFill" left="0" top="0" width="100%" height="100%"></Image>
<StackLayout top="0" left="0" width="100%" height="100%">
... usual content here
</StackLayout>
</AbsoluteLayout>
Related
I'm trying to make a progress bar that moves across the screen with some text below it.
Here's my template:
<StackLayout v-else id="loadingContainer">
<StackLayout class="progress-bar">
<StackLayout class="progress"></StackLayout>
</StackLayout>
<StackLayout horizontalAlignment="center">
<Label id="progressText" :text="loadingText" />
</StackLayout>
</StackLayout>
and here is the CSS:
.progress-bar {
height: 20px;
width: 100%;
position: relative;
background-color: #f8f8f8;
}
.progress {
position: relative;
height: 100%;
border-radius: 0px 2px 2px 0px;
animation-name: fill;
animation-duration: 2s;
animation-timing-function: ease-in;
animation-fill-mode: forwards;
animation-direction: normal;
width: 0%;
}
#keyframes fill {
0% {
width: 0%;
background-color: #6a2d91;
}
100% {
width: 100%;
background-color: #6a2d91;
}
}
Both display the text as I expect but the progress bar behaves very differently on iOS and Android. Android just shows the progress bar as full the whole time and never animates it. iOS shows the appropriate gray background until the `animation-duration is up and then the bar just shows full, it doesn't animate it. I have keyframes working on this page doing other things but I can't get this figured out.
By default child components in a vertical StackLayout will stretch out to fill the width. You should set horizontalAlignment to left on the progress bar layout, though it gets what you wanted on Android, on iOS horizontalAlignment / verticalAlignment is not respected during animation.
So I would suggest using JavaScript APIs to animate Width / Height, presented by Alex.
You may also use the default Progress and increment the value at internals to achieve similar look.
I want to know how I can see the 100% of a picture in a header with CSS. The problem is that when I add the image to the header, the image does not resize, so I have to make bigger the header, but I don't want that.
.header{
background-image: url("../IMAGES/myimage.png");
width: 100%;
height: 100px;
}
Basically I want to achieve a header with an image resized, so I will be able to see the full image in a header with the dimensions that I want on the header. I am new in CSS. Feel free to ask any question. Thank you.
how I can see the 100% of a picture in a header with CSS
to see a background image in it's entirety, use
background-size: contain;
.header{
background-image: url("//placehold.it/300x100/cf5");
background-size: contain;
background-repeat: no-repeat; /* add this to not repeat it as pattern */
background-position: 50% 50%; /* center it? */
height: 100px;
}
<div class="header"></div>
than id needed you can additionally play with background-position to set it's position
If you want the image to fill the entire header area without distortions use
background-size: cover;
.header{
background-image: url("//placehold.it/300x100/cf5");
background-size: cover;
background-repeat: no-repeat; /* add this to not repeat it as pattern */
background-position: 50% 50%; /* center it? */
height: 100px;
}
<div class="header"></div>
if you don't care that the image distorts but you want the image to stretch-to-fill than use
background-size: 100% 100%;
.header{
background-image: url("//placehold.it/300x100/cf5");
background-size: 100% 100%;
height: 100px;
}
<div class="header"></div>
Without exactly knowing what you really want to achieve, I think you're trying to do, what the background-size property does.
With background-size: cover; you can force the background image to cover the whole area of the according element (like a div).
Your code example would look like
.header{
background-image: url("../IMAGES/myimage.png");
width: 100%;
height: 100px;
background-size: cover;
}
Just use:
max-width: 100%;
On the css of the image, that will make it be at max, the 100% of the width of the container.
CLARIFICATION
For an image inside the container header, max-width will do the trick. If it's a background image, background-size:contain will maintain the image INSIDE the header, while cover will expand the image to cover the whole header.
.header > img {
max-width: 100%;
height: 200px;
width: 600px;
}
.header2 {
background-image: url("https://source.unsplash.com/random/500x500");
background-size: contain;
background-repeat-x: no-repeat;
height: 200px;
width: 600px;
}
.header3 {
background-image: url("https://source.unsplash.com/random/500x500");
background-size: cover;
background-repeat: no-repeat;
height: 200px;
width: 600px;
}
<div class="header">
This is my header
<img src="https://source.unsplash.com/random/500x500" alt="and this is my image inside it" />
</div>
<div class="header2">
This is my second header with a background contained inside
</div>
<div class="header3">
This is my third header with a background covering it
</div>
I have a really cool photo as my website portfolio but i cant get it responsive and fit the div. It fills the entire div but the entire photo isnt fittinf properly. I am using bootstrap.
This is my css
.bg1 {
background-image: url (../img/brain.jpg);
background-size: 100%;
height: 600px;
}
try this:
.bg1{
background-image: url (../img/brain.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
Demo link
More info here: Perfect Full Page background
You can try load your image with a <img> tag, and add img-responsive class which is supported by Bootstrap. See more in http://www.w3schools.com/bootstrap/bootstrap_ref_css_images.asp
I'm trying to set a background image for a page in IONIC 2.
I have tried multiple things.
my Html code**strong text**
<ion-content class="myview" padding class="letsstart">
</ion-content>
**my scss**
.myview {
background-image: url('../../img/letsstart.jpg');
// background-image: url('/img/letsstart.jpg');
// background-image: url('img/letsstart.jpg');
// background-image: url('../img/letsstart.jpg');
// background-image: url('./img/letsstart.jpg');
}
Above mentioned ways are not working..
is something I am missing ??
Try including a variable in ts with your url as value and then use the variable in html.
TS
constructor(){
this.backimg = 'img/letsstart.jpg';
}
HTML
<ion-content class="login-content" style="background-image: url('{{backimg}}')">
</ion-content>
SCSS
.login-content{
width: 100%;
height: auto;
background-repeat: no-repeat;
background-size: 100% 100%;
}
It worked for me. Hope this helps you too.
Don't use background-image:
background-image: url('../../img/letsstart.jpg');
Use background:
background: url('../../img/letsstart.jpg');
To make it work use the following format. This should work for both web and the device.
background-image: url('../img/lola_akinmade_akerstrom-white_reindeer-1605.jpg');
Credit:
https://forum.ionicframework.com/t/css-body-background-image-not-showing/9649/6
Ionic 3.10.1
Include without quotes and the finish into declaration
page-login {
.login-background{
background: no-repeat fixed center;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
background-image: url(/assets/img/background.jpg);
}
}
Result:
Photo by Samuel Fyfe on Unsplash
Anywhere you are, on any level, keep using the path ../assets/your_folder/your-image.*
ion-content {
background: url("../assets/images/city-view_min_resized.jpg") no-repeat center center fixed;
height: 100%;
}
Hope it helps :)
I am making an interactive map and want to have buttons on it that will change color (separate image) when hovered over, and then link to different images.
I am having a huge problem with making this work... My current css is a mess:
a.button
{
position: inherit;
display:block;
background:transparent url('images/button.png') bottom;
background-repeat: no-repeat;
}
a.button:hover
{
position: inherit;
background-image: url('images/button_hover.png');
background-repeat: no-repeat;
}
#one
{
position: fixed;
left:225px;
top:702px;
}
HTML:
<div id="map"><img src="images/map.png"/></div>
<a href="http://matthewligotti.com" class="button"/>
<img src="images/button.png" id="one"/>
</a>
</div>
So I want the images to be links and hover the same two images for each button the only thing changing would be the links they bring you to. How do I do this?
If you can edit the images, you can combine them into one .png by stacking them on top of each other. Then, if buttons the buttons were 100px x 200px, you could do something like this:
a.button
{
display:block;
height:100px;
width:200px;
background-image:url('1.jpg');
background-position:0 0;
background-repeat: no-repeat;
}
a.button:hover
{
background-position:0 -100px;
}
and
<a href="http://matthewligotti.com" class="button"/></a>
<a href="http://matthewligotti.com" class="button"/></a>
which would switch the top or bottom half of the new double-image being displayed.
does that do what you mean?