/    Sign up×
Community /Pin to ProfileBookmark

hoe do i center or stretch background

like, if the background was huge, but i wanted it to stretch to fit the brweser or screen of whoever was viewing it, how would i do that?

to post a comment
HTML

1 Comments(s)

Copy linkTweet thisAlerts:
@FangJan 16.2006 — <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>stretch background image</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<script type="text/javascript">
// <a href="http://www.quirksmode.org/viewport/compatibility.html">http://www.quirksmode.org/viewport/compatibility.html</a>
function documentSize() {
var x,y;
var test1 = document.body.scrollHeight;
var test2 = document.body.offsetHeight
if (test1 &gt; test2) // all but Explorer Mac
{
x = document.body.scrollWidth;
y = document.body.scrollHeight;
}
else // Explorer Mac;
//would also work in Explorer 6 Strict, Mozilla and Safari
{
x = document.body.offsetWidth;
y = document.body.offsetHeight;
}
// resize background
document.getElementById('bgImg').style.width=x+'px';
document.getElementById('bgImg').style.height=y+'px';
}

window.onload=window.onresize=function() {
documentSize();
}
&lt;/script&gt;

&lt;style type="text/css"&gt;
body, html {
margin:0;
border:0;
}
html {height:100%;}
#bgImg {
position:absolute;
top:0;
left:0;
z-index:0;
}
#contents {
position:relative;
z-index:1;
}
p {margin:5em} /* fill the document */
&lt;/style&gt;

&lt;/head&gt;
&lt;body&gt;
&lt;img id="bgImg" alt="Stretched image" src="background.gif"&gt;
&lt;div id="contents"&gt;
&lt;h1&gt;Contents&lt;/h1&gt;
&lt;p&gt;bla&lt;/p&gt;
&lt;p&gt;bla&lt;/p&gt;
&lt;p&gt;bla&lt;/p&gt;
&lt;p&gt;bla&lt;/p&gt;
&lt;p&gt;bla&lt;/p&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
×

Success!

Help @Lowallyn spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...