Jump to content

Margin Problem


Streamfish
 Share

Recommended Posts

http://portalbird.com/As you see, the first grey box is pushed 100 px down.But, i have set the top margin of that box to be zero:( "container" is the big gray one, and "header" is the smaller and darker one. )#container { width: 450px; height: 900px; background: rgb(200, 200, 200); margin: 0 auto; } #header { width: 300px; height: 80px; margin: auto; margin-top: 100px; background: rgb(100, 100, 100); }It is the darker box inside it that is ment to be pushed 100px down!why does this happen?EDIT:Problem solved, the content of the webpage wil now be removed.The old HTML and CSS is here:XHTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">	<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="no"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Portalbird</title><link rel="stylesheet" href="styleSheet.css" type="text/css" media="all" /></head><body><div id="firstTestContainer">	<div id="container">		<div id="header"> </div>	</div></div>	<div id="secondTestContainer">	<div id="container">		<div id="secondHeader"> </div>	</div></div></body></html>

CSS:

#firstTestContainer {	height: 1000px;	width: 460px;	border: 1px black solid;	float:left;	}#secondTestContainer {	height: 1000px;	width: 460px;	border: 1px black solid;	float: right;	}			#container {	width: 450px;	height: 900px;	background: rgb(200, 200, 200);	margin: 0 auto;	}	#header {	width: 300px;	height: 80px;	margin: auto;	margin-top: 100px;	background: rgb(100, 100, 100);	}	#secondHeader {	width: 300px;	height: 80px;	margin: 0 auto;	background: rgb(100, 100, 100);	}

Edited by Streamfish
Link to comment
Share on other sites

Because top and bottom margins have a strange reverse-inheritance that I've never completely understood. You can solve it by adding "overflow: auto;" to the #container.By the way, you can't use the same id attribute on two different elements in the same page. Use class instead.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...