[HTML/CSS] Centering a table issue

Discussion in 'Homework Help' started by Soviet Union, Apr 13, 2014.

[HTML/CSS] Centering a table issue
  1. Unread #1 - Apr 13, 2014 at 12:13 PM
  2. Soviet Union
    Joined:
    Oct 14, 2011
    Posts:
    1,357
    Referrals:
    1
    Sythe Gold:
    64
    MushyMuncher

    Soviet Union Guru
    $5 USD Donor New

    [HTML/CSS] Centering a table issue

    Hi,

    Essentially I have a table:

    [​IMG]

    However I am having trouble with aligning the table in the center of the page. .

    This is the code I am using pretty much:

    http://jsfiddle.net/ndhqM/456/

    If anyone would be able to explain how to center it that would be awesome. I don't particularly want to set specific pixels as this will only work on specific monitors.

    Any help is appreciated!
     
  3. Unread #2 - Apr 13, 2014 at 1:16 PM
  4. IMakeWebsites
    Joined:
    Apr 13, 2014
    Posts:
    63
    Referrals:
    0
    Sythe Gold:
    0

    IMakeWebsites Member

    [HTML/CSS] Centering a table issue

    I'm only on a phone right now so I can't test this.

    Instead of margin: 0 auto; add:

    Margin-left: 50%;
    Left: 70%;

    I know this would work if your boxes where a specific size ex. 50px width but it might work this way.

    Good luck :)
     
  5. Unread #3 - Apr 13, 2014 at 1:53 PM
  6. Soviet Union
    Joined:
    Oct 14, 2011
    Posts:
    1,357
    Referrals:
    1
    Sythe Gold:
    64
    MushyMuncher

    Soviet Union Guru
    $5 USD Donor New

    [HTML/CSS] Centering a table issue

    I believe I put the above in the correct position and the result can be seen below:

    http://puu.sh/87f34.png

    Seems to have shifted it to the right >_< Unless I put the code in the incorrect place :embar:
     
  7. Unread #4 - Apr 13, 2014 at 2:45 PM
  8. IMakeWebsites
    Joined:
    Apr 13, 2014
    Posts:
    63
    Referrals:
    0
    Sythe Gold:
    0

    IMakeWebsites Member

    [HTML/CSS] Centering a table issue

    The margin-left will make it shift to the right then you have to position it left more.

    I'm not sure but you might have to make the content box relatively positioned or try making your left: 70% to left: -70%

    Wish I could do some trial and error on my computer right now :p.
     
  9. Unread #5 - Apr 13, 2014 at 3:08 PM
  10. Soviet Union
    Joined:
    Oct 14, 2011
    Posts:
    1,357
    Referrals:
    1
    Sythe Gold:
    64
    MushyMuncher

    Soviet Union Guru
    $5 USD Donor New

    [HTML/CSS] Centering a table issue

    When changing the left to any value it did not seem to have any impact on the position of the table other than when I first input the code shifting it completely to the right :huh:

    E.g.:

    [​IMG]

    The column still remained on the right even with negative percentages. I could be wrong but I believe the red font indicates a syntax error?

    I do apologize if some if this is worded in incorrect terminology.
     
  11. Unread #6 - Apr 13, 2014 at 3:14 PM
  12. IMakeWebsites
    Joined:
    Apr 13, 2014
    Posts:
    63
    Referrals:
    0
    Sythe Gold:
    0

    IMakeWebsites Member

    [HTML/CSS] Centering a table issue

    Some browsers are case sensitive so you may need to make the "Left" left as well as the Margin-left to margin-left.

    If you haven't yet try making the position relative (position: relative;) and if -70% does not work with left you can use right: 70%;
     
  13. Unread #7 - Apr 13, 2014 at 3:22 PM
  14. Soviet Union
    Joined:
    Oct 14, 2011
    Posts:
    1,357
    Referrals:
    1
    Sythe Gold:
    64
    MushyMuncher

    Soviet Union Guru
    $5 USD Donor New

    [HTML/CSS] Centering a table issue

    I made all of the corrections and tried adjusting the percentages appropriately but still not luck. >_< I'll remember the case sensitive for future thanks. ;)
     
  15. Unread #8 - Apr 13, 2014 at 3:32 PM
  16. IMakeWebsites
    Joined:
    Apr 13, 2014
    Posts:
    63
    Referrals:
    0
    Sythe Gold:
    0

    IMakeWebsites Member

    [HTML/CSS] Centering a table issue

    Ok so I got the chance to access my dads laptop.

    Here is what I have come up with:

    You can make your CSS like this:
    div {
    /* inset shadow for visual aid only: allow to easily see the div boundaries */
    box-shadow: 0 0 1px black inset;
    }

    #contentBox {
    width: 70%;
    margin: 0 auto;
    }

    #contentBox .column {
    float: left;
    margin: 0 auto;
    width: 50%;
    }

    I kept your content box the same. I think this is what you wanted to do (Hope it is!). I think you wanted your 2 .column's to be 50% of it's parent div, content box, which was 70% of the page. To do this you needed to make the .column's 50% because they are taking 50% of the parent div, not the web page.

    Sorry if that was confusing, hope this is what you meant.
     
  17. Unread #9 - Apr 13, 2014 at 3:37 PM
  18. Soviet Union
    Joined:
    Oct 14, 2011
    Posts:
    1,357
    Referrals:
    1
    Sythe Gold:
    64
    MushyMuncher

    Soviet Union Guru
    $5 USD Donor New

    [HTML/CSS] Centering a table issue

    Yes! This is perfect! Thank you for the help and the explanation :) Whilst it means the columns are a little wider it works perfectly! Thank you again! :D
     
  19. Unread #10 - Apr 13, 2014 at 3:39 PM
  20. IMakeWebsites
    Joined:
    Apr 13, 2014
    Posts:
    63
    Referrals:
    0
    Sythe Gold:
    0

    IMakeWebsites Member

    [HTML/CSS] Centering a table issue

    No problem, I'm happy I realized the problem wasn't margins but dimensions, haha!
     
< Microeconomics | Need help with microsoft access >

Users viewing this thread
1 guest


 
 
Adblock breaks this site