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.

Centering within a <div> using XHTML Strict

Discussion in 'HTML & Website Design' started by briandunning, Mar 13, 2006.

  1. #1
    I'm playing around with XHTML Strict (not Transitional). I made a <div> that contains some images, and I want the images to be centered within the <div>. So far every way I've tried to do this fails validation. I figured that text-align:center within the CSS would do it, but it has no effect on the images. Anyone?
     
    briandunning, Mar 13, 2006 IP
  2. Scott Botkins

    Scott Botkins Peon

    Messages:
    823
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #2
    <center><div></div></center> should work
     
    Scott Botkins, Mar 13, 2006 IP
  3. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #3
    The center element is deprecated and is not valid in either html4.01 nor xhtml1.0 strict.

    div {text-align: center;}
    =========
    <div><img src=some.jpg" alt="" /></div>

    Will render the image centered horizontally within the div.

    cheers,

    gary
     
    kk5st, Mar 13, 2006 IP
  4. kniveswood

    kniveswood Well-Known Member

    Messages:
    764
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    120
    #4
    Or alternatively,
    <div style="text-align:center;">
    ...
    </div>

    The best is still to use kk5st's method and put the style inside your css file.
     
    kniveswood, Mar 13, 2006 IP