Log in

View Full Version : css positioning standard



alexdog1805
02-28-2010, 07:13 PM
for example if i have an index.html:

<div id="banner"><center><img src="image way"></center></div>

and a style.css with

#banner{padding:0;tp:0}

why doesn't the browser do't listen and it doens't put the image on top=0 and it pun standard posotion 5px above?

coothead
02-28-2010, 07:53 PM
Hi there alexdog1805,

it has probably slipped your memory but the body element is one of the elements that has a default margin. ;)

This code example will achieve the effect that you require....


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="language" content="english">
<meta http-equiv="Content-Style-Type" content="text/css">

<title></title>

<style type="text/css">
body {
padding:0;
margin:0;
}
#banner img {
display:block;
width:324px;
height:200px;
margin:auto;
background-color:#999;
}
</style>

</head>
<body>

<div id="banner">
<img src="image-way.jpg" alt="">
</div>

</body>
</html>

coothead

alexdog1805
02-28-2010, 09:16 PM
but now i can't set the top to other elements.for exemple

#text{top:50px;}

how can I do that the browser set the other top?

alexdog1805
03-01-2010, 07:05 PM
does somebody knows?

coothead
03-01-2010, 07:54 PM
Hi there alexdog1805,

does somebody knows?

from the minimal information that you have supplied, it is almost impossible to know what you're problem is. :eek:

Do you have a link to the site in question?

coothead

alexdog1805
03-01-2010, 08:17 PM
well the problem is that if I do like coothead told me it is ok...it appears on top:0 but if I want to put another photo or text for example at top:100px it doesn't listen and it appears next above to image banner.

coothead
03-01-2010, 08:29 PM
Hi there alexdog1805,

does this help...


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="language" content="english">
<meta http-equiv="Content-Style-Type" content="text/css">

<title></title>

<style type="text/css">
body {
padding:0;
margin:0;
}
#banner img {
display:block;
width:324px;
height:200px;
margin:auto;
background-color:#999;
}
#content {
margin-top:50px;
text-align:center;
background-color:#999;
}
</style>

</head>
<body>

<div id="banner">
<img src="image-way.jpg" alt="">
</div>

<div id="content">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
</div>

</body>
</html>

coothead