CSS center problem

Discussion in 'CSS' started by le007, Mar 30, 2012.

  1. #1
    Hi all,

    My class won't center on my page, it just stays at the left? Can anyone see a problem. Thanks

    This is my code, I've declared in the overall body:
    width: 1260px; /*silly width, not 800-friendly yet still small on the next screensize up... might as well go to 960 or something*/
    margin: 0 auto;


    .float {
    position: absolute;
    width: 800px;
    margin: 0 auto;
    margin-top: 90px;
    color: black;
    font-style: italic;
    font-family: times;
    font-size: 4.5em;
    }
     
    le007, Mar 30, 2012 IP
  2. Osho Garg

    Osho Garg Active Member

    Messages:
    50
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    86
    #2
    Share Your Website Link Then I Will Solve Your Problem In Seconds.
     
    Osho Garg, Mar 30, 2012 IP
  3. xXxpert

    xXxpert Well-Known Member

    Messages:
    604
    Likes Received:
    34
    Best Answers:
    9
    Trophy Points:
    165
    Digital Goods:
    7
    #3
    Try
    {
    margin-left:auto;
    margin-right:auto;
    }
     
    xXxpert, Mar 31, 2012 IP
  4. Devitor

    Devitor Peon

    Messages:
    57
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    0
    #4
    Make sure you declare an HTML doctype, that is normally the cause of this issue
     
    Devitor, Mar 31, 2012 IP
  5. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #5
    Doctype declared, I will post links later on. Thanks
     
    le007, Apr 1, 2012 IP
  6. Devitor

    Devitor Peon

    Messages:
    57
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    0
    #6
    Didn't see that you were using absolute positioning.

    left:50%;
    margin-left:-400px;
    Code (markup):
    the value of margin-left just needs to be half of your width.
     
    Last edited: Apr 1, 2012
    Devitor, Apr 1, 2012 IP
  7. heloraghu

    heloraghu Member

    Messages:
    133
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    46
    #7
    donot use any margins any left bottoms
     
    heloraghu, Apr 1, 2012 IP
  8. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #8
    Devitor - No access to computer that has the files on it for a couple of days - I don't understand this at all?

    left:50%;
    margin-left:-400px;
    Code (markup):

    Or what you mean heloraghu?


    Thanks :D
     
    le007, Apr 2, 2012 IP
  9. Devitor

    Devitor Peon

    Messages:
    57
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    0
    #9
    since you have absolute positioning on by using 'left:50%' you are placing the div's left side in the center of the screen.
    You use 'margin-left: -400px;' to set your margin to go to the left negative 400 pixels which is half of what you total width is, this should place the center of your div in the center of the screen.

    Here is an example using the same class you posted originally
     
    Devitor, Apr 2, 2012 IP
  10. Audiomad

    Audiomad Peon

    Messages:
    1,028
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Just take out the absolute positioning margin: 0 auto; is the part that centers it but you are also using a class why not a div or both?

    #float {
    width: 800px;
    margin: 0 auto;
    margin-top: 90px;
    }
    .style {
    color: black;
    font-style: italic;
    font-family: times;
    font-size: 4.5em;
    }
    
    <div id="float" class="style"></div>
    
    Code (markup):
     
    Audiomad, Apr 4, 2012 IP
  11. Devitor

    Devitor Peon

    Messages:
    57
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    0
    #11
    that would work if he wasn't using absolute positioning
     
    Devitor, Apr 4, 2012 IP
  12. intrig

    intrig Member

    Messages:
    109
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    38
    #12
    try doing...

    <div align="center">
    <div class="float">
    bla bla bla
    </div>
    </div>

    its certainly not the best practice but should work ..
     
    intrig, Apr 5, 2012 IP
  13. Audiomad

    Audiomad Peon

    Messages:
    1,028
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #13
    That's how I do all my coding.
     
    Audiomad, Apr 5, 2012 IP
  14. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #14
    I rebuilt the entire page. I've a new problem which I'm starting a new thread with. Thanks for your help ",)
     
    le007, Apr 11, 2012 IP