Не мога да проумея къде греша

brainfreeze

Registered
Целта ми е да float-на два div-a в един parent div, но се получава нещо, което не мога да проумея, както и да разбера къде греша.

Ето ми го HTML-a:

Код:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
	<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">


<head>
	<title>Floating divs</title>
	<meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
	<link type="text/css" rel="stylesheet" href="style.css" />
	
</head>

<body>

	<div id="container">
	
		<div id="div_1">
		Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
		</div>
		
		<div id="div_2">
		Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
		</div>
		
	</div>



</body>
</html>


и CSS-a:


Код:
* {
	margin: 0;
	padding: 0;
}

#container {
	margin: 0 auto;
	width: 800px;
	border: 5px solid red;
}

#div_1 {
	width: 350px;
	background-color: blue;
	color: white;
	float: left;
}

#div_2 {
	width: 350px;
	background-color: green;
	color: white;
	float: left;
}


Ето и какво се получава: (натиснете в/у изображението)




На практика двата diva са в parent-a, но както виждате не личи. Под IE проблема го няма, но под Mozilla & Opera е налице. Нямам идея защо така се получава и какво бъркам.

Thanks in advance!
 
nadness каза:
Задай float: left; и на #container ...както height: auto; и на трите.

Да, това сработи, обаче на мен #container ми е необходим центриран хоризонтално, а когато му задам float: left; се позиционира вляво. Има ли начин да се избегне това?
 
Код:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>bla</title>
		<style type="text/css">
			* { margin:0px; padding: 0px; }
			div#main {
				width:800px; height:auto;
				padding:2px; margin:20px auto;
				border:1px solid red;
			}
			div.left {
				float:left;
				background-color:green;
				color:#FFF;
				width:260px;
			}
			div.right {
				float:right;
				background-color:blue;
				color:#FFF;
				width:260px;
			}
			.clear { clear:both; }
		</style>
	</head>
	<body>
		<div id="main">
			<div class="left">Left container</div>
			<div class="right">Right container</div>
			<br class="clear" />
		</div>
	</body>
</html>
 

Back
Горе