CSS center page alignment

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • FrEaKmAn
    New Member
    • Aug 2007
    • 46

    CSS center page alignment

    Hello

    I'm wondering if I can align some div to the center of the page (horizontal and vertical). We are talking about the option to scroll up/down and that div still stays at the center. I know that this is possible with JS, but what about CSS?

    Thanks in advance
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    Horizontally centered div can be obtained by setting margin: 0 auto; for both body and the required div.
    But for vertically centered div, you would need to give approximate padding-top.

    Or there's always a forbidden way by making a full page table and using valign="middle" and align="center" for it.

    Comment

    • nitinpatel1117
      New Member
      • Jun 2007
      • 111

      #3
      Also you need a valid doctype in order for the margin auto to work in across all browsers.

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5388

        #4
        may be this link helps? it 'dead centers' a div :)

        kind regards

        Comment

        • hsriat
          Recognized Expert Top Contributor
          • Jan 2008
          • 1653

          #5
          Originally posted by gits
          may be this link helps? it 'dead centers' a div :)

          kind regards
          That was really good!

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5388

            #6
            i thought so ... quite clever solution i think :)

            Comment

            • FrEaKmAn
              New Member
              • Aug 2007
              • 46

              #7
              nice thanks :D But on the end I decided for JS and drag feature :D

              Comment

              Working...