CSS Code: The CSS property is used to set the image as background in the text. The background-image property is used to set an image as background. The -webkit-text-fill-color property is used to give the text a transparent color, the background image will show through the text, thus completing the clipping effect.
To center an image, we have to set the value of margin-left and margin-right to auto and make it a block element by using the display: block; property. If the image is in the div element, then we can use the text-align: center; property for aligning the image to center in the div.
As the simplest solution. That is: Create a relative div that is placed in the flow of the page; place the base image first as relative so that the div knows how big it should be; place the overlays as absolutes relative to the upper left of the first image.
To center text in CSS, use the text-align property and define it with the value “center.”
I am creating a web page, where I have an image that I want to place in the center. On the top of that image I want to have input boxes, labels, and a submit button.
I am trying to use this CSS
img.center
{
z-index:-1;
}
but this does not work. When I change the code to
img.center
{
position:absolute;
left:0px;
top:0px;
z-index:-1;
}
it makes the image go behind. But then as I used left:0px
and top:0px
... it puts the image at location 0,0. But I want the image to stay in the center.
To keep the image in the center, I have added this: <div align="center">
.
Is there any way, I can keep the image in the center and make it go behind the boxes, labes, and buttons too?
My HTML page looks like this (I tried to have a background image for my div tag, but no image is appearing on top of it):
<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>
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