how can i modified this plugin http://srobbin.com/jquery-plugins/backstretch/ to auto-keep the background ratio when windows is resize like http://css-tricks.com/examples/FullPageBackgroundImage/css-1.php.
i like the smooth fade effect in "backstrech" i would like to keep
this plugin but if anyone have a better plugin that does what i'm
looking for with the smooth effect between images.
Thanks
try to add this to your Css file
html {
background: url(../img/pattern.png) fixed, url(../img/background-image.jpg) 50% 50% fixed no-repeat;
-moz-background-size: auto, cover; /* Firefox 3.6 */
background-size: auto, cover; /* Chrome, Firefox 4.0+, Safari 4.1+, Opera 10+ and IE9 */
}
Related
I created a landing page for the website www.foscaintepidario.it
But I want the image on it to be centered, and remain centered, also when the browser-view is changed. Changed in the perspective of size, but also the switch from landscape to portrait and the other way around.
In het HTML/CSS I currently make a distinction between the portrait and landscape version, they both have their own image.
Hope you can help me.
you can use css background elements to have a clean view.
background-image: url(url to image);
background-position: center center;
background-repeat: no-repeat;
background-size: cover;
I finally solved it. The solution with the background-image works fine. The only thing I had to add was the height: 100vh parameter!
Thnx for your support
background: #344b68 url(../../data/img/template/background.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
Hello once again Stackoverflow, I have the following question.
Background.jpg is my websites background picture, wich is in 1080p resolution (1920x1080). On the border of the image, it fades to #344b68.
Viewing this on a 720p monitor will cause the picture to reduce in size using background-size: coverbut this will also be increased when viewing this on for example 1440p resolutions.
Now what I want to do is when it's a 720p monitor reduce the image' dimensions with background-size: cover to fit, but when its above 1080p, it stays the same dimentions and just fades in with the static background color (#344b68).
How can I do this, preferibly without JS?
Thanks in advance!
This looks like a job for Media Queries! These are a CSS3 feature that let you specify code to only activate when certain conditions are met. In your case, you want to query the window width:
/* normal styles */
.item-with-background {
background-size: contain;
}
/* overrides when screen is 720px wide or smaller */
#media screen and (max-width: 720px) {
.item-with-background {
background-size: cover;
}
}
Note: Media queries are supported in basically all the browsers (including mobile) except IE 6/7/8. If you REALLY need to have media queries in use in those browsers, there are some polyfills that hack-in that ability.
I've set an image to max-height:100%; of the browser window (with a small padding at the bottom), centred on the page. Currently, I'm having problems keeping the aspect ratio of the image from squashing when the browser is resized (interestingly it shows at the correct aspect ratio when refreshed after a resize).
I've set up an example in codepen. Would appreciate any advice on how to keep the ratio correct.
http://cdpn.io/sHJhl
UPDATE 18/08: I've updated the code in the copepen above. It's now working in all browsers except Chrome, which distorts the image when the browser is resized. Oddly it resizes fine in Chrome when the codepen is in edit mode. I've tested the code from the codepen in my development site and it shows the same issue, so it's definitely not a codepen quirk. Hoping someone can help on this one.
FURTHER UPDATE 18/08: Solved this issue with Chrome by adding max-width:100%, see answer below.
Solved this issue. The image needed max-width:100%; as well as max-height:100%; width:auto; to work in Chrome. I've updated the codepen to show the full working code: http://cdpn.io/sHJhl
Image's parent element .photo-bkg doesn't have any width set, so add it a width: 100%;
.photo-bkg { height:100%; width: 100%; }
That should do the trick.
You want to achieve a full page background right?
This worked for me:
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;
}
source: http://css-tricks.com/perfect-full-page-background-image/
I have a <div> with a background Image.
The <div> size may change over the time.
Is it possible setting the Divs Background image to fit the <div> size?
Lets say I have a div which is 400x400 and an Image which is 1000x1000, is it possible to shrink the image to 400x400 and therefore fit the <div> size?
If you'd like to use CSS3, you can do it pretty simply using background-size, like so:
background-size: 100%;
It is supported by all major browsers (including IE9+). If you'd like to get it working in IE8 and before, check out the answers to this question.
Use background-size for that purpose:
background-size: 100% 100%;
More on:
http://www.w3schools.com/cssref/css3_pr_background-size.asp
Use background-size property to achieve that. You should choose between cover, contain and 100% - depending on what exactly you'd like to get.
You can achieve this with the background-size property, which is now supported by most browsers.
To scale the background image to fit inside the div:
background-size: contain;
To scale the background image to cover the whole div:
background-size: cover;
Use this as it can also act as responsive. :
background-size: cover;
You could use the CSS3 background-size property for this.
.header .logo {
background-size: 100%;
}
Set your css to this
img {
max-width:100%,
max-height100%
}
Wanted to add a solution for IE8 and below (as low as IE5.5 I think), which cannot use background-size
div{
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=
'/path/to/img.jpg', sizingMethod='scale');
}
This should work but will not keep the image aspect ratio:
background-size: 100% 100%;
I have multiple backgrounds with a gradient, and its working for Firefox, Chrome and Safari, with certain media querys for mobile devices.
As usual the problem is Internet Explorer. I used to have a conditional stylesheet for IE where I just loaded a single background image, but as far as I know, IE10 wont support < !--If IE--> in my CSS.
Ideally I would like to get the css3 gradient and separate background images working on all browsers, I'v been happy to use a single background image for all IE browsers, but so far the single background image wont work for IE.
CSS in main style.css
body{
font:14px 'questrialregular', Arial, Helvetica, sans-serif;
margin:0;
width:100%;
color:#797979;
background-image:
url(../img/bknd_img1.png),
url(../img/bknd_img2.png),
url(../img/bknd_img3.png),
url(../img/bknd_img4.png),
url(../img/bknd_img5), -webkit-gradient(radial, 50% 20%, 0, center center, 500, from(#c0deff), to(#509deb));
background-image:
url(../img/bknd_img1.png),
url(../img/bknd_img2.png),
url(../img/bknd_img3.png),
url(../img/bknd_img4.png),
url(../img/bknd_img5.png), -moz-radial-gradient(center center, circle contain, #c0deff, #509deb);
background-attachment:fixed;
background-position:top right, top left, center bottom, bottom right, left bottom;
background-repeat: no-repeat, no-repeat, no-repeat, no-repeat, no-repeat;
background-color:#509deb;
display:block;}
CSS for Internet Explorer: style-ie.css
font:14px 'questrialregular', Arial, Helvetica, sans-serif;
margin:0;
width:100%;
color:#797979;
background-image: url('img/bknd_full_img.jpg');
background-attachment:fixed;
background-position:center top;
background-repeat: no-repeat;
background-color:#fff;
display:block;
}
The problem is that you only give the gradient and multiple background to WebKit (using the old syntax) and Firefox (using the slightly newer syntax). There is no way that either IE or Opera can display the gradients or multiple backgrounds as you don't supply their prefixes or the none prefixed version.
IE10 implements gradients using the latest and final syntax, without prefixes. The latest Opera does too, and so does recent Firefox. IE10 doesn't need your conditional comment code, as it will work the same way as the other browsers.
The radial gradient should become something like:
background-image:
url(../img/bknd_img1.png),
url(../img/bknd_img2.png),
url(../img/bknd_img3.png),
url(../img/bknd_img4.png),
url(../img/bknd_img5.png),
radial-gradient(circle closest-side at center, #c0deff, #509deb);
More details on the syntax changes can be found on the IE blog [0] and the spec [1]
[0] http://blogs.msdn.com/b/ie/archive/2012/06/25/unprefixed-css3-gradients-in-ie10.aspx ,
[1] http://dev.w3.org/csswg/css3-images/#radial-gradients