Absolute Middle Alignment for Images

Posted on 2006-05-10
Last Modified: 2008-03-06

I have the attribute

align="absmiddle" in an image tag. Unfortunately with XHTML Strict, this is not allowed. Can anyone please tell me the CSS equivalent.

I know that

vertical-align:absmiddle is not valid in cSS

and that

vertical-align:middle does not give the desired effect. Thank you
Question by:REA_ANDREW
    LVL 14

    Expert Comment

    LVL 14

    Expert Comment

    LVL 8

    Accepted Solution


    get the image size.

    write this out as a style sheet:

    .img_style {
       position: absolute;
       left: 50%;
       margin-left: - (WIDTH/2);
       top: 50%;
       margin-top: - (HEIGHT/2);

    <img class="img_style" src="....." />

    The left and top margins are NEGATIVE numbers (one half the size).

    Try that and see.....

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    When writing CSS, there are a few simple rules that will make your life easier.    1. Using ‘* {box-sizing:border-box;}’. Using this will wrap all your elements in a nice little compact box-model that will give you the width you want, like so... …
    CSS is a visual language used to classify objects and define rules about how they should be displayed. CSS skills aren’t restricted to developers anymore, there is a big benefit to having a basic understanding of the language, regardless of your occ…
    In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
    In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now