Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

css vertically aligning spans

Tags:

css

I'm trying to keep everything aligned vertically but can't seem to figure it out

here is the css

fieldset span{
    padding:50px 10px 0px 10px;
    float:left;
    clear:none;
}
fieldset span.buttons{
    float:right;
}

and the html markup

<fieldset class="remove">
    <span class="itemtype">story</span>
    <span class="itemtype">53547</span>
    <span class="title">New online education program aimed at curbing dangerous drinking</span>
    <span class="buttons">
        <a href="#" target="blank"><img src="img/edit.png" alt="edit story" />Edit</a>
        <a href="#7" target="blank"><img src="http://www.bibliomania.com/graphics/read.gif" alt="read story" />Read</a>
    </span>
    <input type="hidden" name="featured[items][53547]" value="story" />
</fieldset>

and a fiddle you can see how the image pushes down also the text in the 'a' tag text needs to be corrected as well

edit

using background image would be nice but that makes the image go under the text see new fiddle

like image 389
mcgrailm Avatar asked May 26 '11 13:05

mcgrailm


People also ask

How do you vertically align items in CSS?

The vertical-align property in CSS controls how elements set next to each other on a line are lined up. In order for this to work, the elements need to be set along a baseline. As in, inline (e.g. <span> , <img> ) or inline-block (e.g. as set by the display property) elements.

How do you vertically align in TD?

HTML | <td> valign Attribute The HTML <td> valign Attribute is used to specify the vertical alignment of text content in a cell. Attribute Value: top: It sets the content to top-align. middle: It sets the content to middle-align.

How do I make div content vertical-align middle?

You can just set text-align to center for an inline element, and margin: 0 auto would do it for a block-level element.


2 Answers

Try this :

fieldset span a img {
    vertical-align: middle;
}

Vertical-align is a CSS property that is often misued to align text. However its aim is to align images (and yes, it also does align text but only in table).

See CSS-tricks.com - What is vertical-align

Fiddle to test

like image 171
Clement Herreman Avatar answered Sep 22 '22 14:09

Clement Herreman


What about just using the padding for both top & bottom:

fieldset span{
    padding:25px 10px 25px 10px;
...

http://jsfiddle.net/SxCH2/5/

like image 45
gutierrezalex Avatar answered Sep 19 '22 14:09

gutierrezalex