PDA

View Full Version : help required for background positioning using css


s_dragons_lair_c
06-26-2005, 02:25 PM
hi,
i need some help with background positioning. i have an image as a background and i have used this code for positioning it in the center:

body {
background-color: #000000;
background-image: url(background.png);
background-repeat: no-repeat;
background-position: center 20px;
background-attachment:fixed;
}

in background-position, i earlier used "center center" but with that the image was vertically going beyond the size of the page from upwards( i mean the full image was not coming vertically from the top), so i used 20 px. but now the full image is not coming in the browser from downwards.
so can anyone tell me how i can make the full image to appear as background

s_dragons_lair_c
06-27-2005, 04:11 AM
can someone please help me :unsure:

domedia
06-27-2005, 12:39 PM
"center center" should work just fine. Not understanding completely what is wrong. Can you post your complete html/css code?

s_dragons_lair_c
06-28-2005, 12:00 PM
OK, I will post the whole code. This is the code for the external style sheet:

/* CSS Document */

body {
background-color: #000000;
background-image: url(background.png);
background-repeat: no-repeat;
background-position-x: center;
background-position-y: 20px;
}
a:link {
color: #CC9900;
text-decoration: none;
font-size: 12px;
font-family: Geneva, Arial, Helvetica, sans-serif;
font-weight: bold;
}
a:hover {
text-decoration: none;
color: #FFCC66;
font-size: 12px;
font-weight: bold;
font-family: Geneva, Arial, Helvetica, sans-serif;
}
a:active {
text-decoration: none;
color: #FFFF33;
font-family: Geneva, Arial, Helvetica, sans-serif;
font-size: 12px;
font-weight: bold;
}
a:visited {
color: #CC9900;
text-decoration: none;
font-family: Geneva, Arial, Helvetica, sans-serif;
font-size: 12px;
font-weight: bold;
}
a {
font-size: 12px;
font-family: Geneva, Arial, Helvetica, sans-serif;
font-weight: bold;
text-decoration: none;
color: #C39300;
}

And this is code I've used in the web page:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Welcome to GAMEZCLUB</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x ; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
<link href="style_sheet.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style22 {font-size: 12px; font-weight: bold; font-family: Geneva, Arial, Helvetica, sans-serif; }
.style24 {
color: #999999;
font-size: 12px;
}
-->
</style>
</head>

<body onLoad="MM_preloadImages('button2.png','button4.pn g','button6.png','button8.png','button10.png','but ton12.png')">
<div id="Layer5" style="position:absolute; width:241px; height:552px; z-index:4; left: 187px; top: 288px;">
<iframe src="cheats_1_frame.htm" height="575" width="271"></iframe>
</div>
<div id="Layer6" style="position:absolute; width:518px; height:41px; z-index:5; left: 187px; top: 239px;">
<table width="519" height="41" border="2" cellpadding="5" cellspacing="5" bgcolor="#333300">
<tr>
<td width="460" height="10">
<div align="center">
<pre class="style22"><span class="style24 "># <a href="cheats_a_1.htm">A</a> <a href="cheats_b_1.htm">B</a> <a href="cheats_c_1.htm">C</a> <a href="cheats_d_1.htm">D</a> <a href="cheats_e_1.htm">E</a> <a href="cheats_f_1.htm">F</a> <a href="cheats_g_1.htm">G</a> <a href="cheats_h_1.htm">H</a> <a href="cheats_i_1.htm">I</a> <a href="cheats_j_1.htm">J</a> <a href="cheats_k_1.htm">K</a> <a href="cheats_l_1.htm">L</a> <a href="cheats_m_1.htm">M</a> <a href="cheats_n_1.htm">N</a> <a href="cheats_o_1.htm">O</a> <a href="cheats_p_1.htm">P</a> <a href="cheats_q_1.htm">Q</a> <a href="cheats_r_1.htm">R</a> <a href="cheats_s_1.htm">S</a> <a href="cheats_t_1.htm">T</a> <a href="cheats_u_1.htm">U</a> <a href="cheats_v_1.htm">V</a> <a href="cheats_w_1.htm">W</a> <a href="cheats_x_1.htm">X</a> <a href="cheats_y_1.htm">Y</a> <a href="cheats_z_1.htm">Z</a></span></pre>
</div></td>
</tr>
</table>
</div>
<div id="Layer3" style="position:absolute; width:84px; height:115px; z-index:7; left: 35px; top: 286px;"><img src="menu%20background.png" width="149" height="202"></div>
<div id="Layer2" style="position:absolute; width:110px; height:91px; z-index:8; left: 44px; top: 319px;">
<p><a href="homepage.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('home','','button2.png', 1)"><img src="button.png" alt="Home" name="home" width="134" height="21" border="0"></a><a href="roms.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('roms','','button4.png', 1)"><img src="button3.png" alt="ROMs" name="roms" width="134" height="21" border="0"></a><a href="emulators.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('emulators','','button6. png',1)"><img src="button5.png" alt="Emulators" name="emulators" width="134" height="21" border="0"></a><a href="cheats_a_1.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('cheats','','button8.png ',1)"><img src="button7.png" alt="Cheats" name="cheats" width="134" height="21" border="0"></a><a href="forum.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('forum','','button10.png ',1)"><img src="button9.png" alt="Forum" name="forum" width="134" height="21" border="0"></a><a href="contact_us.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('contact_us','','button1 2.png',1)"><img src="button11.png" alt="Contact Us" name="contact_us" width="134" height="21" border="0"></a></p>
</div>
<div id="Layer4" style="position:absolute; width:76px; height:48px; z-index:9; left: 664px; top: 57px;"><img src="Logo.png" width="80" height="66"></div>
</body>
</html>


By the way, I've not provided any data in the lower part. Is that why the whole image is not visible. If yes, how can overcome that because I won't provide images and stuff till the lower part in all the pages. And half the background won't look good.

domedia
06-28-2005, 01:00 PM
This should work just fine. Still don't see the problem.
background-position: center center;

s_dragons_lair_c
06-29-2005, 06:27 PM
can u send me a web page with the code. ill see if it works fine.