SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    My true identity MaxS's Avatar
    Join Date
    Nov 2004
    Location
    New York
    Posts
    768
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Centering a Content Box ( Horizontal/Verticle )

    I am trying to figured out how to center a content box. The content box should remain centered when new content is added to it.

    Code:
    {
    	position: relative;	
    	margin : 0 auto;
    	width: 25%;
    	height: auto;
    	border-style: dotted;
    	border-width: thin;
    }
    Now...How could I possibly get it centered vertically?

  2. #2
    SitePoint Guru DocType's Avatar
    Join Date
    Feb 2005
    Posts
    827
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sounds like job for JavaScript, since the top and bottom margins would change depending on the height of the content box, it would have to expand vertically in both directions, not just downward.

    You might want to post your question in the JavaScript forum.

  3. #3
    get into it! bigduke's Avatar
    Join Date
    May 2004
    Location
    Australia
    Posts
    847
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well if you want it to be super vertically centered then yes, you'll need some js, otherwise use this:
    HTML Code:
    .class {
        position:relative;
        top:25%;
        height:50%;
    }
    Its a h4x0r3d way of doing it but if you have just enough content, it works.

  4. #4
    My true identity MaxS's Avatar
    Join Date
    Nov 2004
    Location
    New York
    Posts
    768
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the help guys!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •