Results 1 to 5 of 5

Thread: Centering an image

  1. #1
    Join Date
    Jan 2007
    Location
    Close to the fridge
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Centering an image

    Is there a way to have am Image always centered (using different resolutions) using CSS if so do I use relative or static or another ?

  2. #2
    Join Date
    Oct 2006
    Location
    New York, NY, USA
    Posts
    262
    Thanks
    42
    Thanked 24 Times in 24 Posts

    Default CSS / w3.org

    May I refer you to http://www.w3.org/Style/Examples/007/center.html#block.

    The way I understand it, apply AUTO left/right margins (margin-left: auto; margin-right; or margin: 0 auto. Then. because IE doesn't support AUTO margins, add text-align: center; (usually in body specs, and then apply text-align: left; for content div).

    Frankly, I wish they would reinstate good old, no-nonsense CENTER.

  3. #3
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Code:
    <div style="text-align:center;">
       <img src="myimage.jpg" alt="text">
    </div>
    - Mike

  4. #4
    Join Date
    Jan 2007
    Location
    Close to the fridge
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks ...that worked well

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Frankly, I wish they would reinstate good old, no-nonsense CENTER.
    We don't -- that there scurvy dog be bulk presentational markup
    The way I understand it, apply AUTO left/right margins (margin-left: auto; margin-right; or margin: 0 auto. Then. because IE doesn't support AUTO margins, add text-align: center; (usually in body specs, and then apply text-align: left; for content div).
    It's not as simple as that. One centres a block-level element by making sure its left and right margins are equal and of the correct width to hold the element in the centre (which is what the margin:auto stuff is all about). However, images are inline elements, and so should be centred with text-align:center. Then IE comes along and treats certain elements (specifically, tables) as if they were inline, even though they're actually block-level, so we have to centre those with text-align as well.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •