Bootstrap Endless Background Image - css

In this Layout:
choose Agency-Demo,
they use a fullscreen background image. And when you begin to scroll, the background is overlayed by the content (div containers). When you scroll you can see that the background changes and is again overlayed by the following content.
How they find the correct positioning for the content depending on the screen size of the device?
And how they add different classes depending on the scroll-height?
Is it possible to do this with bootstraps standard functionality?

The Agency-Demo is using the css cover selector. The cover keyword specifies that the background image should be scaled to be as small as possible while ensuring both its dimensions.
Results:
• Fills entire page with image, no white space
• Scales image as needed
• Retains image proportions (aspect ratio)
• Image is centered on page
• Does not cause scrollbars
• As cross-browser compatible as possible
• Isn't some fancy shenanigans like Flash
.demo-header {
text-align: center;
background: url('assets/img/bg-header.jpg') no-repeat center center scroll;
color: #fff;
-webkit-background-size: cover;
background: cover;
padding: 100px 0;
}
For cross browser compatibility you can use the following code.
html {
background: url(images/bg.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}

Related

Bootstrap Mobile background image

I have a background image set. When I look on a mobile device the background image is different sizes on different pages even though they are all linked to the same stylesheet with this code
Site is 'treyscode.com' you can go to the different pages and see the size difference. Page is still not finished so don't give me too hard of a time :)
'''
body {
background: url(../image/blackhole.jpg);
background-repeat: no-repeat;
background-position: center;
background-attachment: fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
height:100%;
width:100%;
}
'''
Why would different pages show the background image as a different size?
Actually it depends upon your content of the webpage.As you have set the background-repeat property to no-repeat so it makes you think that it's of different size. In actual the image is constantly sticked and it's of same size on every page.
If you'll remove the above background-repeat property then you can see the difference which i'm talking about.

How to stop image from scaling when screen size changes

Right now my wordpress site is set up so the images scale when the screen size changes. I was hoping that, instead, the image can remain at a specific size in the center of the screen and become cropped equally on the left and right when the screen size changes.
I have tried max-width:none but that doesn't keep and crop the image in the center of the page.
Site: Zxndesignco.com
The image in question is the only image on the home page. I only know CSS so I was hoping there is a CSS solution.
Example of what i'm taking about: https://gatewaydemo.wordpress.com/
Thanks for the help.
The general idea is to not use an image, and make that image the background-image of that hero section instead. So delete the img tag and add something like this CSS to .sow-image-container height: 400px; background: url(https://zxndesignco.com/wp-content/uploads/2016/12/HomeImg.jpg) center top; background-size: cover
body{
background-repeat:no-repeat;
background-position:center center fixed;
background-image:url(https://zxndesignco.com/wp-content/uploads/2016/12/HomeImg.jpg);
background-attachment:fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
height: 100%;
}
.white{
font-size: 24px;
color: #fff;
}
<div>
<p class="white">Here are some words</p>
</div>
Usually in the body or in a div. I like this group because it covers all the browser bases.

Wordpress section background - responsive auto-scaling?

I'm building a wordpress site and I have a section background set. I used an image with 1920px width. On my 1366px screen the image is not scaling, but is cut-off from the right by the pixel difference. Any way (css?) to make the image scale automatically according to the screen size?
Site url: http://www.imprero.com/wordpress/graffitx/
Thanks.
The background size must be contained so that it will automatically fit.
Insert this to the background you are talking about: "background-size: contain;"
Try this.
element{
background: url(images/bg.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}

Scaled, fixed background on iOS devices

I am trying to make a "background" image that both scales to fill the screen, and is fixed (i.e. does not scroll with rest of content.)
I started by trying to use a true background image:
background: url(http://i.imgur.com/DJaWd.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
But as you probably know, using this technique the image scrolls on iOS devices. So, I tried this approach using a CSS and a div:
CSS:
#fixedbg{
background:url('/images/contest_bkg.jpg') no-repeat center center;
position:fixed;
height:100%;
width:100%;
z-index:-1;
top:0;
}
The second approach does stop the image from scrolling, but the image displays 1:1, instead of scaling to fit the screen/viewport size. Any tips on how to get the image to scale while staying locked down?
Try this:
-webkit-background-size: 1600px 1060px;
Of course px is width height of your bakcground image

CSS body background image fixed to full screen even when zooming in/out

I am trying to achieve something like this with CSS:
I'd like to keep the body background image fixed on fullscreen, this is sort of done by the following code:
body
{
background: url(../img/beach.jpg) no-repeat fixed 100% 100%;
}
Now I can verify the window is indeed filled up with that image, at least this works on my Firefox 3.6
However, it screwed up when I tried to zoom in/out (ctrl+-/+), the image just is stretched/shrinked as the page zooms.
Is there a better way of doing this purely with CSS? I didn't find a good property for the background-image.
Or should I start thinking about jQuery to manipulate the width and height on the fly? They were both set to 100% so I reckon that should work "as always" :(
Thanks for any suggestion in advance!
there is another technique
use
background-size:cover
That is it
full set of css is
body {
background: url('images/body-bg.jpg') no-repeat center center fixed;
-moz-background-size: cover;
-webkit-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
Latest browsers support the default property.
I've used these techniques before and they both work well. If you read the pros/cons of each you can decide which is right for your site.
Alternatively you could use the full size background image jQuery plugin if you want to get away from the bugs in the above.
You can do quite a lot with plain css...the css property background-size can be set to a number of things as well as just cover as Ranjith pointed out.
The background-size: cover setting scales the image to cover the entire screen but may mean that some of the image is off screen if the aspect ratio of the screen and image are different.
A good alternative is background-size: contain which resizes the background image to fit the smaller of width and height, ensuring that the whole image is visible but may lead to letterboxing if the aspect ratios are different.
For example:
body {
background: url(/images/bkgd.png) no-repeat rgb(30,30,30) fixed center center;
background-size: contain;
}
The other options that I find less useful are:
background-size: length <widthpx> <heightpx> which sets the absolute size of the background image.
background-size: percentage <width> <height> background image is a percentage of the window size.
(see w3schools.com's page)
Add this in your css file:
.custom_class
{
background-image: url(../img/beach.jpg);
-moz-background-size: cover;
-webkit-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
and then, in your .html (or .php) file call this class like that:
<div class="custom_class">
...
</div>
Here is the simple code for full page background image when zooming
you just apply the width:100% in style/css thats it
position:absolute; width:100%;
Use Directly like this
.bg-div{
background: url(../img/beach.jpg) no-repeat fixed 100% 100%;
}
or call CSS separately like
.bg-div{
background-image: url(../img/beach.jpg);
-moz-background-size: cover;
-webkit-background-size: cover;
-o-background-size: cover;
background-size: cover;
}

Resources