简体   繁体   中英

Vertically align center inside div element

My text have only 1 line and my picture will fit the container height.
I want text and picture to align center vertically.
I try margin top text class with negative value and position relative but nothing work what I really want.

jsfriddle here

HTML

<div id="friend_select">
        <div class="Friend">
            <img class="Picture" src="http://graph.facebook.com/harell/picture?type=square&width=80&height=80" />
            <span class="Name">First Name Last Name 1</span>
        </div>
        <div class="Friend">
            <img class="Picture" src="http://graph.facebook.com/harell/picture?type=square&width=80&height=80" />
            <span class="Name">First Name Last Name 2</span>
        </div>
</div>

CSS

#friend_select{ padding: 5px; width: 400px; height: 500px; }
.Friend{ height: 80px; } 
.Friend .Name{ line-height: 80px; }
.Friend .Picture{ line-height: 80px; width: 80px; height: 80px; }

I propose this fix:

.Friend .Name{ line-height: 80px; vertical-align:top; }

Live demo here: http://jsfiddle.net/keaukraine/WNT7U/

Works in latest Firefox, Chrome and IE down to IE8. For IE7, apply this hack:

.Friend .Name { *zoom:1; }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM