0

How to display a div at center top position of the page, which need to be work under all size of monitors using CSS.

Mainly I get issues on IE, where not aligned properly.

velu
  • 1
  • 1
  • The answer is here: http://stackoverflow.com/questions/2498552/horizontal-and-vertical-center-text-in-html/2857692#2857692 – Marco Demaio May 18 '10 at 15:11

4 Answers4

3

For margin: 0px auto; to work width needs to be provided

style:

div#center 
{
 width: 300px;
 margin: 0px auto;
}

html:

<div id="center">content</div>
LukeP
  • 10,422
  • 6
  • 29
  • 48
  • Why do you use the unit "px" for the attribute value "0"? That's not neccessary and usually omitted. – Leo Jan 11 '10 at 23:14
  • typo, apologies. Typed in 10px at first as an example, then I've noticed OP asked for top of the page. Will leave it for reference though :D – LukeP Jan 11 '10 at 23:17
  • accepted :D I was just surprised because everybody else here was using it... so it doesn't seem well established?! – Leo Jan 11 '10 at 23:21
0

CSS

div
{
margin : 0px auto;
}
Zaje
  • 2,281
  • 5
  • 27
  • 39
0

Are you comparing the rendering in both IE and another browser by switching back and forth? If so, you might be noticing a shift because of the scroll bar. IE reserves the space for the scrollbar, while browsers such as Firefox only show the window scroll when necessary.

Ryan Joy
  • 3,021
  • 19
  • 20
0

div#center { width: 300px; margin: 0px auto; }

not working on IE...

Santhosh
  • 19,616
  • 22
  • 63
  • 74