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.

Alignment with XHTML 1.0 Strict

Discussion in 'HTML & Website Design' started by norfstar, Sep 21, 2005.

  1. #1
    I'm using the Strict doctype for the first time and I'm having difficulty getting things to center align. The align attribute is not allowed in XHTML 1.0 Strict, and I've tried both

    text-align: center;
    Code (markup):
    and

    margin-left: auto; margin-right: auto;
    Code (markup):
    in the hope that it would get Internet Explorer to centrally align. Unfortunately it doesn't :(. Can anyone point me in the right direction?

    Note: The above CSS acheives the desired effect in both Firefox and Opera.
     
    norfstar, Sep 21, 2005 IP
  2. fryman

    fryman Kiss my rep

    Messages:
    9,604
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    370
    #2
    Have you tried something like that?
     
    fryman, Sep 21, 2005 IP
  3. norfstar

    norfstar Peon

    Messages:
    1,154
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I've found a slightly messy solution in that the content can be contained with a 100% wide table with one cell that is text-aligned to center. Still, if anyone knows of a better way, that would be great.
     
    norfstar, Sep 21, 2005 IP
  4. norfstar

    norfstar Peon

    Messages:
    1,154
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I have yep (found that page on Google too ;)), but unfortunately it doesn't appear to be working. It's a <div> that I need centrally aligned, and text-align seems to work for things like text, images etc. only.
     
    norfstar, Sep 21, 2005 IP
  5. nevetS

    nevetS Evolving Dragon

    Messages:
    2,544
    Likes Received:
    211
    Best Answers:
    0
    Trophy Points:
    135
    #5
    Put your div in a container div and center align the container:


    
    <html>
    <head>
     <style>
     .container{ 
      background: green; 
      padding: 20px; 
      border: 1px solid black; 
      text-align:center
     }
     .mydiv{
      border=1px solid blue; 
      background: red; 
      font-weight: bold; 
      padding: 20px;
     }
     </style>
    <head>
    <body>
    <div class="container">
     <div class="mydiv">some text</div>
    </div>
    </body>
    </html>
    
    HTML:
     
    nevetS, Sep 21, 2005 IP
    norfstar likes this.
  6. norfstar

    norfstar Peon

    Messages:
    1,154
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks nevetS - that worked perfectly in IE :).
     
    norfstar, Sep 21, 2005 IP
  7. nevetS

    nevetS Evolving Dragon

    Messages:
    2,544
    Likes Received:
    211
    Best Answers:
    0
    Trophy Points:
    135
    #7
    A bit of a warning about using xhtml strict - the document will not get properly parsed unless you use a proper DOCTYPE declaration - and IE does not support xhtml - it parses it as html and implements some bug fixes brought about in IE6. If you use a proper http header (application/html+xml) ie will not display it at all.
     
    nevetS, Sep 21, 2005 IP