Code2Design.com

User login

Programming

The Layout

Navigation

Popular content

Resources

Who's online

There are currently 2 users and 12 guests online.

Online users

  • DyemAquamma
  • Maryonne

Another way to do ABSMIDDLE with CSS?

I'm just checking up my website, www.creaturefeature.info, with validator.w3.org, and apparently the align="absmiddle" function is not supported on all browsers. Is there a way to do something similar with CSS to avoid some browsers not supporting it?


Submitted by Ataru on November 24, 2007 - 2:18pm.
printer friendly version

absmiddle

I have never even heard of anything like "absmiddle". However, I take it that it stands for "absolute middle". If so, one of the following will work:

<center><p>Old HTML style center</p></center>


<div style="margin: 0px auto; width: 100px;">
CSS center
</div>


"absmiddle" is not a standard attribute

"absmiddle" is a proprietary attribute for vertical centering which is why it isn't supported by all browsers. The closest you could get in CSS would probably be to use "vertical-align:middle".

<img src="my-image.png" style="vertical-align:middle">


absmiddle

Actually, vertical-align:middle puts the center of an image at 1/4 em above the text baseline, not at the center of the line height. This doesn't match what absmiddle looks like. I have found the following CSS to approximate 'absmiddle' better:

IMG.absmiddle {
vertical-align: middle;
margin-bottom: .25em;
}

You might be tempted to adjust the top margin by -.25em so as not to muck with the line height, but this can cause problems with elements above, such as lines in tables, so I don't do it.


Bingo

THANK YOU. You seem to be the first, and only, person on the entire internet to figure this one out. It was the .25em trick that did it.


THANK YOU!

Been racking my brains with this one for a while. Thanks so much! The .25em margin-bottom definitely did the trick!


absmiddle

Guess vertical-align:middle; CSS directive works exactly the same way as align=absmiddle attribute as of now [just tested with the latest FF, Opera, Chrome and IE - 20090429]. Make sure the CSS I posted propagates to the element correctly - use Firebug for FF if necessary to make sure of it.


Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <br> <br /> <h3>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use BBCode tags in the text, URLs will be automatically converted to links
More information about formatting options



Like what you see?

Why not add more? C2D is looking for other Christian Web Masters who would like to help write articles for this site. If you have expericance in FLASH, CSS/HTML, PHP/MySQL, PhotoShop/GIMP, Blender, Javascript, or just General Design - our users would love to hear what you have to say. Contact Us

delicious   digg   reddit   magnoliacom   newsvine   furl   google   yahoo   technorati