Two floating divs won't align within parent div

Got a really simple question: if I have a 400px wide div, and in in two floating 200px wide divs, why won’t they align properly?

<div style="background-color: #000000; width:400px; height:300px; padding:0; margin:0">
* <div  style="background-color:#f000aa;  padding:0;  margin:0;  height:100px;  width:200px;  float:right;"></div>
* <div  style="background-color:#f0f0ee;  padding:0;  margin:0;  height:100px;  width:200px;  float:left;"></div>
</div>

you can see they have margin and padding set to 0 so I don’t understand what’s going on (screenshot attached)

Hi,

They are aligned for me ok, you don’t actually have those asterisk’ in there do you?


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>untitled</title>
<style>
.wrapper {
  width: 400px;
  height: 300px;
  background: #000;
}
.right {
  float: right;
  height: 100px;
  width: 200px;
  background: #f000aa;
}
.left {
  float: left;
  height: 100px;
  width: 200px;
  background: #f0f0ee;
}
</style>
</head>
<body>
<div class="wrapper">
  <div class="right"></div>
  <div class="left"></div>
</div>
</body>
</html>

no, no asterisk’ those were somehow added during copying and pasting…

well, you code works! why didn’t mine :expressionless:

Hi David,

When I removed the asterisks after copying and pasting, it worked fine so I think they are somehow in your code.

Jim

Were you using something like Microsoft Word to generate that code?