• Home
  • About James Mills
Blue Orange Green Pink Purple

Posts Tagged ‘css’

You can use the search form below to go through the content and find a specific post or page:

May 29

Centre a div using absolute positioning

For all your CSS lovers out there… there have been many times I have wanted to centre a div in the exact centre of the screen… the centre from head to toe and left to right. I have never managed to achieve this and speaking to fellow developers they have also struggled to find the answer to this. It was obviously possible as there are many website that have managed to achieve this affect and so it was only a matter of time till I really needed to do this and hunt down the answer… and today was that day.

It’s actually quite simple if you put your mind to it. Using absolute positioning you can position an element by taking it out of the document flow. Other elements in the normal flow of the document will act as though the absolute positioned element was never there.

width:970px;
height:710px;
position: absolute;
top:50%;
left: 50%;

By setting the left position to 50% it will set the div to start in the centre of the screen. By adjusting the left margin by a value half of the size of the div we are centring, we can move the entire div to the left and place it directly in the centre of the page.

width:970px;
height:710px;
position: absolute;
top:50%;
margin-top:-355px;
left: 50%;
margin-left:-485px;

and that’s it done… until the next time…

James Mills Blog

  • Recent Posts
    • A little advice about cars if you live in Teesside
    • Eventually back from Malta
    • Some great support…
    • Joggler apstore update
    • Still trying!
  • My online DNA
    • Bookmarks on Delicious
    • Digg
    • LinkedIn
    • Music on Last.fm
    • Photos on Flickr
    • Twitter
    • Video on Vimeo
  • Tags
    css domain names events facebook jgm web design joggler koodoo creative life tools malta molly my shopping assistant networking news north east personal portfolio refre refresh teesside SuperMondays tesco tesco api tjam web dev tools wedding
  • Archives
    • August 2010 (1)
    • May 2010 (1)
    • April 2010 (1)
    • March 2010 (2)
    • January 2010 (1)
    • November 2009 (1)
    • October 2009 (1)
    • September 2009 (1)
    • August 2009 (3)
    • July 2009 (3)
    • June 2009 (1)
    • April 2009 (1)
    • March 2009 (2)
    • February 2009 (2)
    • December 2008 (1)
    • November 2008 (1)
    • October 2008 (2)
    • September 2008 (1)
    • August 2008 (1)
    • July 2008 (3)
    • June 2008 (2)
    • May 2008 (7)




  • Home
  • About James Mills

© Copyright James Mills Blog. All rights reserved.
Designed by FTL WordPress Themes by ImHosted Website Hosting

Back to Top