Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertically align multiple lines beside a floated image

<li> 
    <a href="viewBook.php?bookId=<?=$bookId?>"> 
         <img style="float:left; clear:left; padding-left:10px; width:50px; height:75px;" src="http://dummyimage.com/50x75/000/fff" / >
         <span style="line-height:75px; padding-left:5px; color:grey;"><?=$count?>.</span>
         <span style=""><?=$title?></span>
     </a>
</li>

because i wanted to make a large clickable anchor area, so i have to throw everything inside an anchor. problem is because my title may be multiple lines. how could i actually vertically align to center of the image and preventing the next line of title from going below of the image.

demo link: jsfiddle.net/9wJRG/3

like image 690
user723360 Avatar asked May 01 '11 13:05

user723360


1 Answers

You can drop the two span elements and replace them with a single span element like this:

<li> 
    <a href="viewBook.php?bookId=<?=$bookId?>"> 
        <img src="http://dummyimage.com/50x75/000/fff"/>
        <span id="text">
            <?=$count?>. <?=$title?>
        </span>
    </a>
</li>

and then use the following CSS for that span:

#text {
    display: table-cell;
    width: 100px;
    height: 75px;
    padding: 10px;
    vertical-align: middle;
}

Working example on jsFiddle.

Hope this helps !

like image 146
Valentin Flachsel Avatar answered Sep 25 '22 15:09

Valentin Flachsel