1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How can I center a div class container horizontally?

Discussion in 'CSS' started by chrisj, Mar 28, 2013.

  1. #1
    I searched the web for solutions but none centered this horizontally on the page. I tried
    margin-right: auto; and margin-left: auto; and tried margin 0 auto:
    What's the solution?
    Thanks.
     .container10
     {
     border:1px solid #000000;
     background: #00FF00;
     padding:0px 0px 0px 0px;
     width:980px;
     height:264px;
     margin:0px 0px 0px 0px;
     }
    Code (markup):

     
    chrisj, Mar 28, 2013 IP
  2. GMF

    GMF Well-Known Member

    Messages:
    855
    Likes Received:
    113
    Best Answers:
    19
    Trophy Points:
    145
    #2
    I'm pretty sure you didn't ;)

    http://lmgtfy.com/?q=center+div+horizontally
    Code (markup):
    Golly, so many results

    Bonus: How to use a search engine

    http://www.kidzworld.com/article/1900-search-engine-tutorial
    Code (markup):
     
    GMF, Mar 28, 2013 IP
  3. chrisj

    chrisj Well-Known Member

    Messages:
    606
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #3
    Wow. You're being kind of a jerk.
    The searches I found orginally didn't work for me that why I've asked for help here.
    Any other help from any one else would be appreciated.
     
    chrisj, Mar 28, 2013 IP
  4. GMF

    GMF Well-Known Member

    Messages:
    855
    Likes Received:
    113
    Best Answers:
    19
    Trophy Points:
    145
    #4
    I'm being kind of a jerk because your question could be EASILY fixed by searching.

    Well, seems you are not going to do work on your own, so here: Replace your margin with this

    margin:0 auto;


    Here is a jsfiddle, so you can see it working

    http://jsfiddle.net/MB3eA/


    If it doesn't on your site... there would be something else prohibiting it
     
    GMF, Mar 28, 2013 IP
    browntwn likes this.
  5. chrisj

    chrisj Well-Known Member

    Messages:
    606
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #5
    I did search. I did find margin: 0 auto; I added it and it still didn't work, before I ever posted here.
    So, I thought I'd get help with guidance as to what I might need to look at in regard to "be something else prohibiting it". So, I am doing the work on my own. Why don't you search online to find an ego deflater, and follow the directions there.
     
    chrisj, Mar 28, 2013 IP
  6. GMF

    GMF Well-Known Member

    Messages:
    855
    Likes Received:
    113
    Best Answers:
    19
    Trophy Points:
    145
    #6
    Is it my problem that you don't show us the whole code of your site? :rolleyes:

    If you had posted that, I wouldn't be such a jerk, because before I respond, I usually try it out. But now, all I see is some css for a class called .container10

    Since I am no psychic, I cannot see the rest of your code, so I can't possibly know if there is something prohibiting the horizontal centring.
     
    GMF, Mar 28, 2013 IP
  7. chrisj

    chrisj Well-Known Member

    Messages:
    606
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #7
    No, it's not your problem that I have a code issue, your problem is that you jump to negative conclusions, enjoy putting people down, enjoy being sarcastic, and assume they're not telling the truth. Instead of simply saying in the beginning "why don't you show us more code", which would be helping people in this forum, insteading of using it as a place to make yourself feel superior. I'm sure when the sun rises tomorrow my issue will be resolved, yours probably not. I'll post this on another forum.
     
    chrisj, Mar 28, 2013 IP
  8. wiicker95

    wiicker95 Well-Known Member

    Messages:
    438
    Likes Received:
    37
    Best Answers:
    10
    Trophy Points:
    100
    #8
    A container with a fixed width and height? Bad idea. Nulling margins and padding in like that? Bad idea.

    If your code is this bad all along, no doubt you'll have issues. You should check if its parent is floated. If so, you cannot center it.
     
    wiicker95, Mar 28, 2013 IP
    deathshadow likes this.
  9. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #9
    If you are that thin skinned, you're lucky I didn't reply to this one -- since my response would have said what Wiicker95 did, but with more expletives, interjections and general 'half assed code' bashing. Though usually I don't take the LMGTFY approach because it pisses me off when people make that assumption as well. You wouldn't be asking if the solutions you had found didn't work! It's also funny to see some users being more acerbic than me to the nubes...

    The fixed width ALONE would set me to full froth given it's automatically accessibility trash... much less the fixed height which treads into serious herpaderp territory in all but the rarest of circumstances.

    But again, we can't tell without seeing more, since CSS without the HTML it's applied to, the HTML around it, and the CSS of the things applied to all the rest is pretty much useless.
     
    deathshadow, Mar 28, 2013 IP
    Sensei.Design likes this.
  10. rolodex

    rolodex Well-Known Member

    Messages:
    364
    Likes Received:
    37
    Best Answers:
    5
    Trophy Points:
    175
    #10
    I'm no expert at this, my css is also messed up like crash. But when I'm stuck like this, can't center divs and shit, like wiicker95 said, your parents is floated pun intended.

    Then smack some new divs on top of your .container10 div and class it and put clear:both;.
    It's not advisable to smack things up, but at least I have an excuse.

    Now smack that piece up and set your hopes high and promise that on your next project you will carefully code it clean and tidy. Promise.

    I like to start my css feeling tidy, clean and hoping that at the end it will structure beautifully. But then during design, I will hammer everything I got till that navigation appears like I want it to be. Then it got messy and I thought of starting over.

    The feeling of starting over. Fresh. Like standing on top of a mountain in New Zealand. I'm trash talking am I?
     
    rolodex, Mar 29, 2013 IP
  11. wiicker95

    wiicker95 Well-Known Member

    Messages:
    438
    Likes Received:
    37
    Best Answers:
    10
    Trophy Points:
    100
    #11
    This is exactly why people shouldn't use photoshop and paint arsty stuff with it when building websites. Some stuff you design just aren't web deployable, no matter how neat and pretty they might be.

    Although it seems like you're crapping nonsense, your post actually makes perfect sense (well, at least the context): you mention one of the most common problems when it comes to web designing! Painting such designs without having established a semantic markup along with web deployable layouts is a road to failiure in any case. This is unfortunately why those nutcrackers on themeforest and other similar sites manage to sell their useless artwork to people that don't know better.
     
    wiicker95, Mar 29, 2013 IP
  12. rolodex

    rolodex Well-Known Member

    Messages:
    364
    Likes Received:
    37
    Best Answers:
    5
    Trophy Points:
    175
    #12
    Leave the themeforest nutcrackers be. DP has got more nutcrackers than nuts. Why the hell more tools than content? Are they using the tools as their contents? It is up to us to set things straight.

    It all has to start from within...................
    (High...How are you?)
     
    rolodex, Mar 29, 2013 IP
  13. rypher21

    rypher21 Active Member

    Messages:
    914
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #13
    There are many solutions in the Internet. Try to search for it again. But I think, it will be helpful if you use margin-left; and margin-top;
     
    rypher21, Apr 23, 2013 IP
  14. karthimx

    karthimx Prominent Member

    Messages:
    4,959
    Likes Received:
    127
    Best Answers:
    2
    Trophy Points:
    340
    #14
    will this help in all browser?
     
    karthimx, Apr 23, 2013 IP
  15. Nosliw

    Nosliw Well-Known Member

    Messages:
    77
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    123
    #15
    Or you can just do it really easy like this:

    margin-right: auto;
    margin-left: auto;

    :)

    And remember!

    body {
    margin-top: 0;
    }

    unless you want a top-margin on your website!
     
    Nosliw, May 5, 2013 IP