I am attaching the 2 sample images I am using so you can get the idea.
This is the body background:
This is the fixed position div's background:
And above those two there is the content. The whole website. Between those two there are some moving stars in pure css with no interaction.
But here comes the problem. While the user scrolls the fixed background breaks in parts, stucks in positioning and sometimes the body background image disappears and shows only color in the back - all that while scrolling.
body {
font-family: 'LatoRegular', 'Lucida Grande', Helvetica, sans-serif !important;
line-height: 21px;
color: #636e7b;
overflow: hidden; /*removes it after preloader quits*/
position: relative;
background: #1d2939 url("../images/backgroundv2.jpg") fixed;
background-repeat: no-repeat;
background-size: 100% auto;
background-position: center top;
}
#fix {
background: transparent url("../images/backgroundv2.png") fixed;
background-repeat: no-repeat;
background-size: 100% auto;
background-position: center top;
width: 100%;
height: 100%;
position: fixed;
top: 0;
left: 0;
z-index: 1;
-webkit-transform: translateZ(0);
}
Any idea will be appreciated.
(This is the bugged version http://i.imgur.com/bn0fG3j.jpg while scrolling)
well, I played around with your code,and it works as you intended, I would probably have done it in some other way, the code seems a bit messy but it does what you trying to achieve, check this fiddle:
http://jsfiddle.net/domusnetwork/Lkrkp/
and maybe tell me if I misunderstood you.
anyways..
I think that your problem comes from the elements you've stack on top of your background,
try using the next code snippet, it's worth a shot:
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;
}
and if that won't help try implementing one of the techniques in the next article:
http://css-tricks.com/perfect-full-page-background-image/
have a nice day :)
Thank you for the answers.
Fortunately I've found the problem. It was the moving stars. They were made by idea from codepen's author using simple css with massive ammount of box-shadows as dots in 3 divs (sizes). Due the high ammount of stars it requires a lot of painting on the page while scrolling. When I removed one of the star sizes the scrolling is fine, the background stopped disappearing and it's all fine.
Seems like performance has to be above all.
Related
CSS background is not covering whole viewport width while using media query #media (max-width: 62.5em)
I tried using background-size: cover, background-position: top left, background-repeat: no-repeat but still nothing works.
here's main CSS styles of that section.
max-width: 100vw;
min-height: 100vh;
background: url(../images/bg-hero-desktop.svg);
background-color: #ebfbff;
background-size: cover;
background-repeat: no-repeat;
padding-top: 20rem;
padding-left: 5rem;
This is a fairly common error that I experience at times while working on layout.
The problem is NOT with the background of the html component, but rather with the layout on your footer, and your footer-cta-box div. These elements are pushing the layout outside of the viewport which is what is making it appear as though the background for the html is not rendering correctly. If you use "Inspect" in your browser to temporarily take out those elements you will see that the html background renders correctly! You're doing things right!
I'm not sure exactly how you want the footer and footer-cta-box to be laid out on the page, or else I could help you to get them in the right place, but those are the culprits of the problem.
html, body {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
body {
background: url(https://www.nasa.gov/images/content/296150main_2-226.jpg) no-repeat center center fixed;
background-size: cover;
}
main {
color: white;
}
<main>Hello world</main>
try
background-size: contain;
or
background-size: 100%;
instead of
background-size: cover;
For some reason, my background images disappear in Microsoft edge when using background-attachment: fixed. However works fine in IE, Chrome and Firefox.
css is as followed:
header
{
text-align: center;
color: #eee;
background: url(../img/portfolio/66.jpg);
background-size: cover;
background-position: 70% 0%;
background-attachment: fixed;
background-repeat: no-repeat;
}
Any ideas?
Regards,
Steve
I have similar issue on my new parallax project, i am not sure is it because i set my div background-attachment: fixed; or overflow:hidden.
But when I tried to move my background css to innner div like below, my problem solved.
<div class"header"><div class="bg"></div></div>
I've got this snippet in my <body>:
<div class="hero">
...content...
</div>
Nothing too special I figured. My CSS contains a "background:" in the class for the image. The CSS looks like this and it works:
.hero {
position: relative;
background: url(http://www.example.com/img/background.png) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
text-align: center;
color: #ef4d39;
padding-top: 110px;
min-height: 500px;
letter-spacing: 2px;
font-family: "Montserrat", sans-serif;
left: 0;
width: 100%;
}
But when I change it to this (one of the many ways I tried to make it local instead of absolute) it doesn't work:
background: url("img/background.png") no-repeat center center fixed; //Should be the proper way
background: url('img/background.png') no-repeat center center fixed; //Found it with single quotes in tutorials as well
background: url(img/background.png) no-repeat center center fixed; //No quotes since the original snippet doesn't contain quotes
background-image: url("img/background.png") no-repeat center center fixed; //Found this tag in tutorials as well
I'm quite flabbergasted (but I'm not that quite of a programmer as well) but I can't figure out why the original line works and the other lines I tried do not work. This was tested offline. Can anyone explain why and how I can make it work for relative images?
Edit:
Thanks to the comment of DBS I figured what was wrong, the right context should be:
background: url("../img/background.png") no-repeat center center fixed;
The .css is in a subfolder "css" and the image is in a subfolder "img". Thanks for the help you guys!
I recommend you no put these images at the same site, maybe they there are but you can't see them.
You must attach this images on html (look for img tag), inside your div, then you can put that in css for each one in addition would be nice set this orders apart. Try that:
background-repeat:no-repeat;
background-attachment:fixed;
background-position:center;
Surely you was seeing just one, but there was all of them use your browser debugger to check if they are there (press f12).
I hope I have helped.
I'm really new to coding and I am having some trouble.
I want to put a background image under all of my page elements that fits the entire screen. But when I try to do so the white coloring that is apart of all of the p's and h's that I've added overlap the image making the page look funky. Only part of the page gets the background image.
Here's the code I added to the css file.
html {
background: url('imgurl') no-repeat center center fixed;
background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
-webkit-background-size: cover;
}
The html and css files are undoubtedly linked. Also, I used imgurl in my example code, but the actual code links to the right url.
Can't tell without showing a fiddle.
My guess will be doing this so it removes the background on the elements you mentioned.
h1, h2, h3, p {
background: none;
}
one of the easiest ways to accomplish this is to use the following css
#backgroundImage {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
z-index: -1;
}
and here's a fiddle: http://jsfiddle.net/usrp7yom/
My site has to be responsive and I'm supposed to build it "mobile-first".
It's a one page site and each section is divided by an svg image.
So far I've gotten it the width resize perfectly by using background-size:cover; but a small part at the bottom of the image gets cut off. I've tried adjusting the height (auto, 100%, random pixel value) but that doesn't seem to do anything :/
Any ideas?
#breakpink{
background-image: url(../images/break_pink.svg);
background-repeat: no-repeat;
background-size: cover;
height: 100%;
text-indent: -9999px;
}
Full code:
http://jsfiddle.net/duyBE/
Same problem happened for me. There is a solution for this problem that is posted in the accepted answer on this page: CSS: Full Size background image
The solution was to use: background-size: 100% 100%
But there was a drawback, that is when you zoom out the background along with the content, the "body" background appears at the bottom!
Use "background-size: contain" instead of "background-size: cover",
1 background-size : cover
Property value "cover" will make the image to cover available space, if the image is small then it will be scaled up to cover available space, If the image is big then it will be scaled down to cover the available space, in either case, there is a chance that image may get cropped in order to fill the available space.
Pros: It will cover the entire available space.
Cons: Image may get cropped.
2 background-size : contain
"contain" will make the image scale up or down to fit inside the available space.
Pros: Full image is displayed.
Cons: Image may be look stretched. And sometimes you will see empty space around the image.
html {
background: url(../images/break_pink.svg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
This will probably fix your problem
I was having a similar problem. I've added a padding-bottom: 10px; and it worked for me.
add a margin at the bottom of the element:
#breakpink{
background-image: url(../images/break_pink.svg);
background-repeat: no-repeat;
background-size: cover;
height: 100%;
text-indent: -9999px;
margin-bottom:10px;
}
Had similar issue where the bottom of my header image was getting cut off. Resolved it by using
background-size: contain;
I had a similar issue. It turned out that the image file was damaged in some strange way. Opening the image in the file system worked, the image was OK, but it produced this error in the browser. I deleted the image file and downloaded it again and the image was displayed appropiately with the css rules.
add a min-height property
#breakpink{
// other codes are here
min-height: 150vh;
// to see area of the image
border: 2px solid red;
}
body{
margin: 0;
padding: 0;
background: url(image.jpg);
background-size: auto;
background-size: cover;
height: 100%;
text-indent: -9999px;
margin-bottom:10px;
background-position: center;
font-family: sans-serif;
}