Is there any way to make a background image stretch rather than repeat?
Not using any kind of cross-browser compatible CSS (there is the background-size property however.)
If this is directed at any browser in particular, it might be possible. Otherwise, you'll need to use an <img> and stretch that.
Here's how you do it in recent browsers:
body {
background-image: url(bg.jpg);
-moz-background-size: 100% 100%; /* Gecko 1.9.2 (Firefox 3.6) */
-o-background-size: 100% 100%; /* Opera 9.5 */
-webkit-background-size: 100% 100%; /* Safari 3.0 */
-khtml-background-size: 100% 100%; /* Konqueror 3.5.4 */
}
Otherwise, using an <img>:
img#background {
/* height: 100%; Note: to keep ratio, don't use height */
left: 0;
position: fixed; /* or absolute, if you like */
top: 0;
z-index: -1;
width: 100%;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With