Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Background-size:cover, 1px whitespace to the left

Tags:

html

css

I have a small problem on my site about background-size:cover I have been testing it in Firefox all along, but when i load the page in Google Chrome, i get 1px white all to the left. When i use background-position:-1px the white edge left goes away (but then i get it to the right). Is there any way to fix this, and still keep the cover?

I applied this to my body: background:url("images/baggrund.jpg") no-repeat center center fixed; background-size: cover

I can not link to the site at the moment, but hope i described it clear enough.

Thanks in advance

Edit: added a screenshot, top comes from firefox, bottom from Chrome.

Screenshot

like image 486
user1765065 Avatar asked Jan 17 '13 09:01

user1765065


People also ask

What is cover background-size?

background-size:cover; means the background image will always fit the whole div , you won't be left with any empty spots in your div background-size:100% 100% won't leave any empty space too, but of course this will detroy the original image aspect ratio.

What is background-size cover in HTML?

cover: It is used to resize the background image to cover a whole container element. Syntax: background-size: cover; Example: This example illustrates the use of the background-size property whose value is set to cover. HTML.

How do you size a background image?

The background-size property is used to set the background image size using CSS. Use height and width property to set the size of the background image.


5 Answers

Try this:

background: background:url("images/baggrund.jpg") no-repeat 49% center fixed;
background-size: cover;

In chrome, when you use "background-size: cover", if the xpos of background-image is no less than 50%, you will meet that problem.

So, the xpos is set to 49% (or 49.9% to reduce the error) instead of "center" will fix that problem.

My English is not good, i hope you know what i mean.

like image 90
DragonWong Avatar answered Oct 17 '22 22:10

DragonWong


Changed background-size: cover; to background-size: 100%;. Worked for me!

like image 42
Aliis Avatar answered Sep 28 '22 15:09

Aliis


That did not work for me, because i used background cover, but i just added a chrome specific line to set my background-size to 101%, that seems to fix it (for the eye). Thanks for the input.

like image 9
user1765065 Avatar answered Oct 17 '22 23:10

user1765065


101% might work fine but you could also try this fine-grained solution:

background-size: calc(100% + 1px);
like image 2
Rick Davies Avatar answered Oct 17 '22 22:10

Rick Davies


You could apply the background property to the body tag, which would cause it to cover the whole page.

You could also try applying the following style to the body and html tags:

html,body{
  padding:0;
  margin:0;
}
like image 1
Kevin Bowersox Avatar answered Oct 17 '22 22:10

Kevin Bowersox