Link to home
Start Free TrialLog in
Avatar of Michel Plungjan
Michel PlungjanFlag for Denmark

asked on

Square div?

Why is the red div not more square?
I would really like a 1x1 pixel div

Thanks
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <title></title>
  </head>
  <body>
<div id="container" style="width:200px;height:200px; border:1px solid green"></div>
<script>
var newDiv = document.createElement('DIV');
  newDiv.style.position =  'absolute';
  newDiv.style.width =  '3px';
  newDiv.style.height = '3px';
	newDiv.style.left = '50px';   
	newDiv.style.top = '50px';   
	newDiv.style.border = "1px solid red";   
	newDiv.style.zIndex = 100;   
  document.getElementById('container').appendChild(newDiv)
</script>
  </body>
</html>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Phatzer
Phatzer
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Michel Plungjan

ASKER

Hmm, that works - but why?
Because otherwise the browser classes nothing as text, and as the text size will be bigger than 1px, so is the DIV, as is my understanding. The transparent GIF is your friend!