img和文本垂直对齐

时间:2013-09-22 17:15:30

标签: html css

<div class="card">
<img class='sound' src='https://www.google.com/images/srpr/logo4w.png'>
<div class='txt'>
 this is a sentence.this is a sentencethis is a sentence.
 </div></div>

.card{
    margin:5px 14px;
    border:thin solid blue;
}
.sound{
    width:32px;
    height:32px;
    cursor:pointer;
}
.txt{
    display:inline-block;
    margin-left:25px;
    vertical-align:middle;  //doesn't work
    border:thin solid red;
}

如何将.txt div与.sound图片的中间对齐? 小提琴是here

3 个答案:

答案 0 :(得分:1)

将垂直对齐放在.sound

.card{
    margin:5px 14px;
    border:thin solid blue;
}
.sound{
    width:32px;
    height:32px;
    cursor:pointer;
    vertical-align:middle;
}
.txt{
    display:inline-block;
    margin-left:25px;
    border:thin solid red;
}

http://jsfiddle.net/hWejY/1/

答案 1 :(得分:1)

vertical-align: middle插入课堂声音

.card{
    margin:5px 14px;
    border:thin solid blue;
}
.sound{
    width:32px;
    height:32px;
    cursor:pointer;
    vertical-align:middle
}
.txt{
    display:inline-block;
    margin-left:25px;
    vertical-align:middle;
    border:thin solid red;
}

DEMO

答案 2 :(得分:1)

vertical-align:middle;

应该是.sound