Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Sep 2011
    Posts
    274
    Thanks
    49
    Thanked 1 Time in 1 Post

    Div Margin 0 Auto does not center

    This has me perplexed.

    I have a div with id=buttons and
    margin-right: auto;
    margin-left: auto;
    yet it displays as left aligned.

    Why?

    http://www.doig.com.au/test/venom/

  • #2
    New to the CF scene
    Join Date
    May 2012
    Posts
    9
    Thanks
    0
    Thanked 1 Time in 1 Post
    if you want align center of div content than use text-align:center"

    or

    if you want start this div from center than give it to any static width:900px.


    when you give 100% width of div than it start form left, and margin: 0 auto not work in this case
    Last edited by sushil553; 05-09-2012 at 12:30 PM.

  • Users who have thanked sushil553 for this post:

    SRD75 (05-09-2012)

  • #3
    Regular Coder
    Join Date
    Sep 2011
    Posts
    274
    Thanks
    49
    Thanked 1 Time in 1 Post
    @ sushil553

    Giving the div a width fixed it.

    Thank you.

  • #4
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,749
    Thanks
    22
    Thanked 1,838 Times in 1,822 Posts
    Good morning SRD75,
    To center an element you need three things:
    1. a valid DocType
    2. an element with a width
    3. that elements right/left margins set to auto


    You can center an image the same way by changing it from a inline to a block level element with display: block;
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad

  • #5
    New to the CF scene
    Join Date
    May 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try like this:

    Margin: 0px auto;


  •  

    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
    •