How to set Background image that cant be repeated - html

While doing PSD to html i have got a background image that cant be set to repeat using css repeat property because images is not consistent like a pattern , its like a full page width/ height image that will require me to set its width height same as page without repeating it , so how do i get it in a way that images is also loaded as background and site speed is also not disturbed , Please help me with , should i simply set its background image for container div ? or somethig else ??

You can use a CSS property for that:
html {
background: url(images/bg.jpg) no-repeat center center fixed; /*Your image here*/
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
Check this link for more information about that :
http://css-tricks.com/perfect-full-page-background-image/
The compatibility is here:
http://caniuse.com/background-img-opts
PD: don't forget the prefixes vendors

Related

HTML background no repeat

How to fit a background image in html without it repeating to cover the whole page? Is there a HTML code for it or do I have to use a CSS code?
There are two CSS properties you can use to control the size and repetition of a background image:
background-repeat
background-size
In order to set as a background image that covers the target element, you would use the values no-repeat and cover, like such:
targetelement {
background-image:url('example.jpg');
background-repeat:no-repeat;
background-size:contain;
}
If you'd like to learn more about these CSS properties and their possible values, have a look at these two pages:
https://www.w3schools.com/cssref/pr_background-repeat.asp
https://www.w3schools.com/cssref/css3_pr_background-size.asp
The best solution for your question is adding background-repeat:no-repeat or background-size: cover to your CSS or your element's style tag.
For example:
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;
}
If you insist on using HTML only, you would have to resize the element according to your image, or the other way around. Your question refers to a page's background image, so for my openion CSS or style is the only way to achieve this.

Full size background without resizing

I'm facing this trouble for quite some time now, have tried n number of options but still no luck.
I have this background image :
Which I want to make as the background of my website. I added it as a full sized background, but I don't know why it always gets resized and becomes something like this.
Here's my css code for the background image.
body
{
background: url('../images/home.jpg') no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
I'm really unsure how to fix this! Please guide me in the correct way.
The background-size: cover property in CSS3 stretches your images to fit the background of the element you have specified, which in this case your body.
Edit: As others have mentioned, using background-size: contain would give you the most desirable result as it is defined by the following:
contain
This keyword specifies that the background image should be scaled to be as large as possible while ensuring both its dimensions are less than or equal to the corresponding dimensions of the background positioning area.
The link below also has other properties that may give you your desired results:
Source:https://developer.mozilla.org/en-US/docs/Web/CSS/background-size
Try to use background-size:contain instead of background-size:cover. Maybe that is more appropriate.
If you want to keep your image in proportion you would want to use
background-size: contain;
However the issue with this is it will keep the background in proportion, so if your window is not the same proportions you will have white space around. Building off #Sebastien 's fiddle I can show you what I mean -
http://jsfiddle.net/j0n19rw5/5/
You could try re-sizing the image itself to work better with contain.
But if you want it to cover the background you would probably be best using cover. One trick is to crop the image to the space (if you know a general sizing).
You can get away without stretching it too much with a method like this one :
https://jsfiddle.net/r3qpe4dm/1/
But it will still cut off your image at smaller sizes.
To be sure, split the background property for each sub-attribute :
body
{
background-image: url('http://i.stack.imgur.com/ZQinh.jpg');
background-position: center center;
background-attachment: fixed;
background-repeat: no-repeat;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
http://jsfiddle.net/Paf_Sebastien/j0n19rw5/1/
Edit:
Add this to your CSS since your HTML/body seem to have a low height:
html, body {height: 100%;}

Background image resizing

I'am trying to design a website with a background image that should stretch in height and width
accordingly when the browser window is resizing. It is complicated to explain what exact behaviour I would like to achieve, for this reason here is the website that does it perfectly:
http://de.wix.com/website-template/view/html/709?originUrl=http%3A%2F%2Fde.wix.com%26number-of-page%3D1%26position-in-page%3D4
I used background-size set to everything possible as well as background-width set to 100%, but
I could not achieve such a behaviour.
Have you tried using the below CSS? This fills the page background with the image.
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;
}
Without any HTML or CSS of your own, it's impossible for us to truly help you, but generally this behavior can be achieved with the following property: background-size: cover
background-image: url('URLGOESHERE');
height: ???;
background-size: cover;
As long as you specify an explicit height (pixels) and do not specify a width, this property should cause the background-image to resize while maintaining aspect ratio.
JSFiddle Example.

Background Image distortion in IE10 and moving the background with content flow?

I have a webpage with a background image and a form which i have placed at the center of this webpage.
For background size to be working in ie 8 i have used background-size.htc polyfill
My requirement is background image should move with form content flow , that means when error messages appears below each input field the height of the form will increase that should also increase the height of the background image ,it should be relative to the bg image.Currently,its working in all browsers except ie what shoud i do for that?
Another thing in ie10 same bg image distorts? I'm attaching the screen shot of it.
If you want to cover the background image to entire browser window at all times. please try 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;
}

Make background image move when you move the page

Is there a way to make the background image move when you scroll the page up and down, whenever i scroll up and down the background image stays still but I want it to move with the page, is that possible?
Simply set the attachment to fixed.
background-attachment:fixed;
If you have a large image, you can use background-size.
For example:
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;
}-
background-size does what it tells you. Using cover as the attribute, the background image is scaled to fill the entire background, thus getting rid of the scrollbars when using an image larger than your screen.
background-attachment?
Mozilla docs: https://developer.mozilla.org/en-US/docs/Web/CSS/background-attachment