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 3 of 3
  1. #1
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    815
    Thanks
    43
    Thanked 6 Times in 5 Posts

    centering a div in ie10

    I am having trouble centering a div in ie10:

    Code:
    div#wrapper {
    width: 800px;
    margin-left: auto;
    margin-right: auto;
    display:block;
    }
    This works in normal view, but when I go to compatibility view the div goes to the left instead of centering.

    Is there something that will work in both views?
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,590
    Thanks
    0
    Thanked 644 Times in 634 Posts
    For compatibility mode you'd use text-align:center the same way you would for IE5.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    815
    Thanks
    43
    Thanked 6 Times in 5 Posts
    Thanks felgall. I've found another way that seems to work:

    Code:
    div#wrapper {    /* centres in normal and compatibility view */
    position: absolute;
    margin-left: -400px;
    left: 50%;
    width: 800px;
    }
    You just halve the width for margin-left.
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)


  •  

    Posting Permissions

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