Loading ...
Sorry, an error occurred while loading the content.

Re: [NH] Re: CSS - Center a

Expand Messages
  • Lotta
    ... Mike, since you have an explicit width and use absolute positioning anyway you can easily center the element by positioning it in the middle of the screen
    Message 1 of 7 , May 3, 2002
    • 0 Attachment
      >My goal was to center the blue square horizontally within the browser
      >window. Since this technique use CSS positioning, I expect it will
      >only work in IE5+ and NS6.

      Mike, since you have an explicit width and use absolute positioning anyway
      you can easily center the element by positioning it in the middle of the
      screen and then give it a negative margin of half it's own width. No
      scripting needed.

      div
      { width: 700px; height: 200px; background-color: blue;
      position: absolute; top: 100px; left: 50%; margin-left: -350px;
      margin-right: auto }

      Lotta
    Your message has been successfully submitted and would be delivered to recipients shortly.