tags:

views:

1191

answers:

5

I am creating a webpage, where i have an image, that i want to place in the center and then on the top of that image i want to have input boxes and labels and submit button.

I am trying to use the css

img.center
{
    z-index:-1;
}

but this does not works. and when i change the code to

img.center
{
    position:absolute;
    left:0px;
    top:0px;
    z-index:-1;
}

if make the image go behind, but then as i used left:0px and top:0px ... it puts the image at loaction 0,0 .. but i want the image to stay in the center.

to keep the image in the center i have <div align="center"> tag.

is there anyway, i can keep the image in the center and make it go behind too???

My .html page looks like this:(i did tried to have a background image for my div tag, but no image is appearing over there)

<html>
<head>
<title>Question of the Week</title>
<style type="text/css">
 body
 {
  background-image:url('images/background.jpg');
  background-repeat:repeat-x;
 }

 .container
 {
 background-image:url('images/center.jpg');
 background-repeat:no-repeat;
 }
 td.cntr {padding-top:50px;}
</style>
</head>
<body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0">

 <table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
   <table width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr>
     <td><div align="left"><img src="images/logo.jpg"></div></td>
     <td></td>
     <td><div align="right"><img src="images/right_logo.jpg"></div></td></tr>
   </table>
  </tr>
  <tr>
   <table width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr>
     <td class="cntr">
      <div id="container">
       <input name="box" type="textbox" />
       <input name="box" type="textbox" />
       <input name="submit" type="submit" />
      </div>
     </td>
    </tr>
   </table>
  </tr>
 </table>
</body>
</html>
+1  A: 

try

body {z-index:0}
img.center {z-index:-1; margin-left:auto; margin-right:auto}

setting the l & r margins to auto should center your image.

ScottSEA
You shouldn't use a negative z-index because not all browsers properly support it.
Ian Elliott
+1  A: 

You can position both image and text with position:absolute or position:relative. Then the z-index property will work. E.g.

#sometext {
    position:absolute;
    z-index:1;

}
image.center {
    position:absolute;
    z-index:0;
}

Use whatever method you like to center it.

Another option/hack is to make the image the background, either on the whole page or just within the text box.

anderstornvig
+6  A: 

Make it a background image that is centered.

.wrapper {background:transparent url(yourimage.jpg) no-repeat center center;}

<div class="wrapper">
 ...input boxes and labels and submit button here
</div>
Emily
i tried your code .. but it did not work. i have edited my question with my code.. could you please have a look at it... again
Zeeshan Rang
You have id='container' but are using .container which is for a class. Either use class='container' in the html or #container in the CSS. You are also missing the background-position:center in the CSS. You can put all the background CSS in one line like in my example above.
Emily
Shame you got short-changed on this one ):
Ian Elliott
+1  A: 

Start at 0 and go up from there, rather than using -1. For instance, set the div containing your inputs and labels to a z-index of 100, and give the image you want to place behind it a z-index of 50.

Alternatively just set the image as the background-image of the div containing the inputs and labels. Since the image is probably illustrative and therefore presentational, it doesn't really need to be an actual img element.

Rahul
+2  A: 

Well, put your image in the back ground of your website/container and put whatever you want on top of that. so say you have:

<div id="container">
   <input name="box" type="textbox" />
   <input name="box" type="textbox" />
   <input name="submit" type="submit" />
</div>

This is be in your code and you CSS would look like:

#container {
    background-image:url(yourimage.jpg);
    background-position:center;
    width:700px;
    height:400px;
}

For this to work tho, you must have height and width specified to certain values (i.e. no %'s) I could help you more specifically if you needed it, but I'd need more info.

Mike