Previous Message
Next Message

What's the proper way to vertically center an element within its parent?

Sent by Ed Seehouse on 3 March 2007 20:08

On 3/2/07, Chris Chen [EMAIL-REMOVED]> wrote:

> I can't seem to be able to style <a> inside <span> to make it centered
> *vertically* inside <span>.

Both of these elements are inline so the only things you can adjust
are the line height and the font size.  If you must for some reason
adjust them vertically then you should be using block elements
instead, or in the last resort apply a display: block; to the elements
in question so you can use the block element CSS rules.  Not a good
idea really, since it wrecks the semantics of your code.

> <span class="span_link"><a href="" >Hello</a></span>

Whatever reason is the span there for?  There's nothing you can do
with that construction that you can't do with just the link.  e.g.

> <a class="span_link" href="" >Hello</a>

If it is part of a menu it belongs in a list, however.

Ed Seedhouse
css-discuss [EMAIL-REMOVED]]
IE7 information --
List wiki/FAQ --
Supported by --
Previous Message
Next Message

Message thread:

Possibly related: