Web Analytics Made Easy -
StatCounter vertical and horizontal centered divs - CodingForum

Announcement

Collapse
No announcement yet.

vertical and horizontal centered divs

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • vertical and horizontal centered divs

    I'm looking to center divs on the x and y axis. I've followed the advice here (http://www.pmob.co.uk/pob/hoz-vert-center.htm) but the problem is there is a difference in layout between the example and what I require.

    I need to center this:

    Code:
    <body>
    <div id="main">
    	<div id="left"><img src="logo.gif" />
            </div>
            <div id="right"><p>text</p>
            </div>
    </div>
    </body>
    unlike the the link which centers everything, I want to center the #main and the image in #left on the left and the text in #right to appear on the right. I've messed around with floats but that didn't help.

  • #2
    Got it

    #main{
    position:absolute;
    height:500px;
    width:700px;
    background:blue;
    left:50%;
    top:50%;
    margin-left:-350px;
    margin-top:-250px;
    }

    #left{float:left;}

    #right{float: right;}

    Comment

    Working...
    X
    😀
    🥰
    🤢
    😎
    😡
    👍
    👎