I'm trying to center box in CSS and HTML

  • Thread starter Sam_
  • Start date
  • #1
15
0
Please help!!

Does anyone here know much about CSS and HTML? I'm trying to center box (have it as a span with a div inside - a box in a box) both horizontally and vertically. I can get it to work just fine in Firefox, but IE won't let me do it. I've tried everything I can think of, I've looked for help online and tried what I found. Nothing. Does anyone know how to do it?
 

Answers and Replies

  • #2
-Job-
Science Advisor
1,146
1
If you're using vertical-align or valign then that's the problem since it doesn't work well for divs in IE.

You should either go with a table cell, or use absolute positioning. For example:
Code:
<html>
<body leftmargin="0px" topmargin="0px">
	Using absolute positioning
	<div style="width:300px;height:300px;border:solid 1px #000000;">
		<div style="left:100px;top:100px;width:100px;height:100px;border:solid 1px #000000;position:absolute;z-index:2">
		
		</div>
	</div>
	Using table cells
	<table cellspacing="0px">
		<tr>
			<td align="center" valign="middle" width="300px" height="300px" style="border:solid 1px #000000">
				<div style="width:100px;height:100px;border:solid 1px #000000;"></div>
			</td>
		</tr>
	</table>
</body>
</html>
 

Related Threads on I'm trying to center box in CSS and HTML

  • Last Post
Replies
11
Views
2K
  • Last Post
Replies
19
Views
958
  • Last Post
Replies
3
Views
59K
  • Last Post
Replies
9
Views
739
Replies
4
Views
903
Replies
3
Views
770
  • Last Post
Replies
0
Views
3K
  • Last Post
Replies
23
Views
2K
  • Last Post
Replies
1
Views
1K
  • Last Post
Replies
17
Views
687
Top