+ Reply to Thread
Results 1 to 3 of 3
Like Tree2Likes
  • 1 Post By Anna
  • 1 Post By callumacrae

Thread: how to place a div in center

  1. #1
    vishal455648 is offline x10Hosting Member vishal455648 is an unknown quantity at this point
    Join Date
    Apr 2011
    Posts
    4

    Smile how to place a div in center

    I have made a simple youtube downloader(http://downvid.co.cc)I want to place google +1 and facebook like in center.I have done

    Code:
    margin-left: 48%;
    but it does not in exactly centre.I have tried text-alignment: center but it does not work.please help.

  2. #2
    Anna's Avatar
    Anna is offline I am just me Anna is a name known to allAnna is a name known to all
    Join Date
    Aug 2007
    Location
    Sweden
    Posts
    6,569

    Re: how to place a div in center

    to center a div, it first need a set size, and then margin left and right set to auto, like:
    Code:
    width: 200px;
    margin-left: auto;
    margin-right: auto;
    The auto parameter makes sure the margin has the same value on the left and right side of the div, as you probably noticed setting margin-left: 48%; only shifts the div to have it's left side somewhere near the middle of the page. In theory it would work if you did something like:
    Code:
    width: 4%;
    margin-left: 48%;
    margin-right: 48%;
    This example would theoretically work (I say theoretically due to the fact that if you mix in a border it would possibly fail on some browsers) since you tell the browser how to use the full width of the page, and would give you a dynamic width on the div, with a fixed with, you need to use the auto parameter for left and right margins.
    hardsteal20 likes this.
    Do you have trouble reaching your site?
    Check here first: News and Announcements


    Don't forget that x10hosting has an irc server as well. Come and join the fun
    server: irc.x10hosting.com, main channel: #x10hosting
    There's a lot helpful users there if need help building your site

  3. #3
    callumacrae's Avatar
    callumacrae is offline not alex mac callumacrae is just really nice
    Join Date
    Dec 2007
    Location
    Wellesbourne, England
    Posts
    5,162

    Re: how to place a div in center

    The first example was the better, although I would have said margin: 0 auto;
    popibaal59 likes this.
    I can customise your phpBB board. Send me a PM.
    lynxphp - info, tutorials and scripts
    "A forum post should be like a skirt; long enough to cover the subject but short enough to keep things interesting."

+ Reply to Thread

Similar Threads

  1. Support Center
    By Corey in forum News and Announcements
    Replies: 5
    Last Post: 03-21-2009, 03:13 PM
  2. Center Ads?
    By Jigzo in forum Free Hosting
    Replies: 1
    Last Post: 07-25-2008, 06:48 AM
  3. Center Picture using CSS
    By sclewin in forum Programming Help
    Replies: 4
    Last Post: 07-22-2008, 05:04 PM
  4. Center content
    By mahlerwd in forum Programming Help
    Replies: 2
    Last Post: 05-21-2008, 10:07 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers