I recently found the problem on a recent question I asked here which was related to what I thought was a Chrome or Safari webkit bug, or maybe something inside my style.css. However, I noticed after a while that my background was slightly moving on resize, and I concluded that when it moved towards the right, a left white border didn't show up from top to bottom on the left side of the screen, but when the background picture moved towards the right hand side then a 2px white border showed up on the left right side. How do I stop the border from moving.
MY CSS:
html {
background: url(/assets/fotball.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
Try this:
background: url(/assets/fotball.jpg) no-repeat center top fixed;
Change your code to this: jsFiddle Live Demo
html {
background: url(/assets/fotball.jpg) repeat center top fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
background-position:;
}
When you use background-size: cover;, it makes no difference to use background:no-repeat or background:repeat. So in this case you can use repeat to solve your problem.
Related
I have the problem that on my website, when I scroll fast on mobile, the background image moves up a bit and a white space at the bottom appears, and then disappears again when I stop scrolling.
I've tried a bunch of solutions to similar problems to prevent this from happening, but I haven't been able to solve it so far.
Here's the my css for the background image:
html {
background: url(bg.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
And a screenshot of the issue:
Try adding the background img to the body aswell like this:
html, body {
background: url(bg.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
Try this code for mobile to the background image show all sides clear images but if your image is big then the image is stretched so first, you need to create a div container to fit your image into the div container.
html, body {
background: url(bg.jpg) no-repeat center center fixed;
background-size: 100% 100%;
}
I have set the background of my web page to an image by doing this
html {
background: url("https://preview.ibb.co/dizdck/beach2.jpg") no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
Then I created a div like this
<div class="container">hi</div>
The problem is that the div has a white background that I don't want to see on the page. I noticed that this white background only appears when I am using bootstrap. Any ideas on why this might be happening and how to fix it?
Here is a codepen with the example: https://codepen.io/bobnooby/pen/GExJmE
you want to do this through css on the body :
body {
background-color: red !important; //set to color
background-image: url("https://preview.ibb.co/dizdck/beach2.jpg") !important; //or set image
}
I generally like to avoid the !important attribute as much as possible. My solution was to include the background image in the same tag as the html and body style attributes. this removed the white div bg color.
html body {
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;
}
I've placed an image in the background of my div with this code:
background: url(../images/cover-image.jpg) no-repeat 50% 100% fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
height: 30rem;
But my problem now is, that I want to move the visible part of the image in the div. The Bottom of the picture should be at the bottom of the div, but I can change everything in the background: (center bottom, 50% 100% etc.) statement, nothing happens.
Can anybody give me a hint?
Try using
background-position: center bottom;
You need to remove the other styling in you 'background' deceleration and just put:
background-position:bottom;
see the fiddle here: https://jsfiddle.net/xerf3z5j/
As one line, this would be:
background: transparent url(../images/cover-image.jpg) center bottom / cover no-repeat fixed;
background-size: cover means that the background image will always take the full width and height of your div.
Should work if you remove those parts:
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
I'm working on a basic html page and I have this background image bg.jpg.
But the problem is depending on the screen size you have and how many pixels the screen has I'm not able to view the whole background image which is something I want.
How do I make the background fixed so you can see the whole background?
If you mean a full page background image than you can simply do it with CSS3 background-size property
body {
background: url(bg.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
If you need to attach it, kinda fixed and shouldn't be scrolled, than use
background-attachment: fixed;
/* This is already used in above CSS declaration using CSS Short Hand*/
You can do something like this:
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;
}
You can read more here: link
Delete your "body background image code" then paste this code:
html
{
background: url(../img/bg.jpg) no-repeat center center fixed #000;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
You can use CSS pseudo selectors.
body:after
{
content: url(your_image)
/* Styling your image here just like a div */
}
Of course those other solutions are OK too, but they only work in latest modern browsers. This pseudo selection solution works in most browsers used today. If you'd like to support even older browsers, like ancient versions of IE, then you can use a div to contain the background image and style it as you'd like.
On this website there's a background image in the footer that should stick to the bottom of the page. I don't mean the visible part of the page, but rather the very bottom of the page. However on pages where the content is short - like this one - it appears some distance above the bottom.
The CSS that I'm currently using is:
html {
background: url(../images/responsive/bg.svg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
outline:0!important;
}
What you're asking to do is more in-line with the concept of a "sticky footer". Example and tutorial
What about using the float attribute:
float: bottom;