SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: XHTML valid - absmiddle - value for CSS?

  1. #1
    ¿uʍop ǝpısdn ʎɥʍ velocd's Avatar
    Join Date
    Aug 2002
    Location
    California
    Posts
    449
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question XHTML valid - absmiddle - value for CSS?

    This issue has been brought up a few times on Sitepoint, unfortunately none of the threads seemed to provide a working solution.

    There doesn't seem to be an adequate way to emulate how - absmiddle - works on images in CSS.

    I've tried vertical-align: middle, but it's off centered.

    Examples.

    http://www.animesystem.com/temp/bad.gif
    <img src="images/go.gif" style="vertical-align: middle" />

    http://www.animesystem.com/temp/good.gif
    <img src="images/go.gif" align="absmiddle" />

    The dudes at W3 should really just fit in the absmiddle value as valid XHTML.

    Does anyone know what CSS can be applied to an image tag to align it to the middle of text and other elements?

  2. #2
    Word Painter silver trophy
    Shyflower's Avatar
    Join Date
    Oct 2003
    Location
    Winona, MN USA
    Posts
    10,024
    Mentioned
    136 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by Solace D.
    This issue has been brought up a few times on Sitepoint, unfortunately none of the threads seemed to provide a working solution.

    There doesn't seem to be an adequate way to emulate how - absmiddle - works on images in CSS.

    I've tried vertical-align: middle, but it's off centered.

    Examples.

    http://www.animesystem.com/temp/bad.gif
    <img src="images/go.gif" style="vertical-align: middle" />

    http://www.animesystem.com/temp/good.gif
    <img src="images/go.gif" align="absmiddle" />

    The dudes at W3 should really just fit in the absmiddle value as valid XHTML.

    Does anyone know what CSS can be applied to an image tag to align it to the middle of text and other elements?
    I may be wrong, but as far as I know, the vertical-align attribute can only be used with tables. However, you can still use hspace and vspace for your images in html. The only problem I have had with it is that you have to play with the pixels quite a bit to get your image where you want it and make sure the text (if you use a float for the image) doesn't break off into a single line under the image.

    I guess if someone else has a better solution, I would like to hear it, too!
    Linda Jenkinson: Content Team Leader
    Creative Web Content
    "Say what you mean. Mean what you say. But don't say it mean." ~Unknown

    March Photo Challenge. "Blue" Poll is open. Vote NOW!
    April Photo Challenge - "A Piece of Paper"

  3. #3
    SitePoint Addict langedav's Avatar
    Join Date
    Apr 2002
    Location
    Rotterdam, The Netherlands
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    maybe it is an option putting the button in a div and position it anywhere you want?

  4. #4
    SitePoint Addict BenANFA's Avatar
    Join Date
    Apr 2003
    Location
    Bath, UK
    Posts
    353
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vertical-align can be applied to any inline element (span, a, img and notibly input to name a few). However the thing to remember is that it is in relation to the current height of the span which will be the height of the tallest bit of content (I think in theory you should be able to set a height with the height attribute, however that doesn't work in Firebird). It may be worth applying the vertical-align middle to all the items you want lined up.

    This code gives some comparisons of the differing attributes (you will need to make a 16px square gif call 16px.gif and a 48px square gif called 48px.gif)

    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html>
    <head>
    <title>Vertical Align Examples</title>
    <style>
    <!--
    p {
    	font-size: 24px;
    	font-family: verdena, ariel, snas-serif;
    	border: 1px solid red;
    	padding: 0px;
    }
    p span {
    	font-size: 14px;
    }
    
    #vcentred span
    {
    	vertical-align: middle;
    	font-size: 24px;
    }
    
    #vcentred #Bit2
    {
    	font-size: 14px;
    }
    
    #vcentred image
    {
    	vertical-align: middle;
    }
    -->
    </style>
    </head>
    <body>
    
    <h1>Vertical Align Examples</h1>
    
    <p><strong>vertical-align: none</strong> This is the paragraph<img src="16px.gif" /><span>This is the span</span><img src="48px.gif" /></p>
    <p><strong>vertical-align: baseline</strong> This is the paragraph<img src="16px.gif" /><span style="vertical-align: baseline">This is the span</span><img src="48px.gif" /></p>
    <p><strong>vertical-align: sub</strong> This is the paragraph<img src="16px.gif" /><span style="vertical-align: sub">This is the span</span><img src="48px.gif" /></p>
    <p><strong>vertical-align: super</strong> This is the paragraph<img src="16px.gif" /><span style="vertical-align: super">This is the span</span><img src="48px.gif" /></p>
    <p><strong>vertical-align: top</strong> This is the paragraph<img src="16px.gif" /><span style="vertical-align: top">This is the span</span><img src="48px.gif" /></p>
    <p><strong>vertical-align: text-top</strong> This is the paragraph<img src="16px.gif" /><span style="vertical-align: text-top">This is the span</span><img src="48px.gif" /></p>
    <p><strong>vertical-align: middle</strong> This is the paragraph<img src="16px.gif" /><span style="vertical-align: middle">This is the span</span><img src="48px.gif" /></p>
    <p><strong>vertical-align: bottom</strong> This is the paragraph<img src="16px.gif" /><span style="vertical-align: bottom">This is the span</span><img src="48px.gif" /></p>
    <p><strong>vertical-align: text-bottom</strong> This is the paragraph<img src="16px.gif" /><span style="vertical-align: text-bottom">This is the span</span><img src="48px.gif" /></p>
    <p><strong>vertical-align: 10px</strong> This is the paragraph<img src="16px.gif" /><span style="vertical-align: 10px">This is the span</span><img src="48px.gif" /></p>
    <p><strong>vertical-align: 25%</strong> This is the paragraph<img src="16px.gif" /><span style="vertical-align: 25%">This is the span</span><img src="48px.gif" /></p>
    
    <h1>Vertical Centred text and Image</h1>
    
    <p id="vcentred"><span>This is the paragraph</span><img src="16px.gif" /><span id="Bit2">This is the span</span><img src="48px.gif" /></p>
    
    </body>
    </html>

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
  •