9

I've looked at a googol google results without finding any that work.

I need to have my div (height 333 px, width 550 px) to be centered horizontally and always be 275 px from the top. Every time I try to do this it just disappears.

captainandcoke
  • 1,085
  • 2
  • 13
  • 16
  • Please share the markup you are using to try to accomplish this. It will help us determine what is going on. – Todd May 11 '11 at 16:52
  • You could use the singleton pattern. See http://stackoverflow.com/questions/3312806/php-static-class-initializer – sebbo Apr 25 '14 at 15:05

3 Answers3

26

If the div should sit on top you have to use position:absolute. Otherwise, the answer from @sdleihssirhc should work.

Example with positioning

#middlebox
{
    position:    absolute;
    top:         275px;
    left:        50%;    /* move the left edge to the center … */
    margin-left: -275px; /* … and move it to the left half the box’ width. */
    z-index:     9999;   /* Try to get it on top. */
}

Use tools like Dragonfly or Firebug to inspect the properties if it still disappears.

fuxia
  • 62,923
  • 6
  • 54
  • 62
0

Depending on the content and context, you could just set that div's margin:

margin: 275px auto 0;
sdleihssirhc
  • 42,000
  • 6
  • 53
  • 67
0

Unless you're thinking of static positioning, I don't think that you would need to use absolute positioning at all. Try this:

<html>
<head>
<title>Test</title>
</head>
<body>
<div style="width:550px; height:333px; background-color:orange; margin: 275px auto">
Is this what you want?
</div>
</body>
</html>
Jimmy
  • 637
  • 5
  • 13