如何垂直对齐表格单元格中的多个图像?

时间:2013-06-16 09:02:43

标签: html css image html-table vertical-alignment

我有3个图像需要在表格单元格中水平和垂直居中。我正在努力垂直对齐它们,它们被困在底部。我该怎么做?

enter image description here

我创建了一个JSFiddle

我的Html是:

<body>
    <br /><br /><br /><br />
    <table>
        <tr>
            <td>aaaaaaaaaaaa</td>
            <td>bbbbbbbbbbbb</td>
            <td>cccccccccccc</td>
            <td>dddddddddddd</td>
        </tr>
        <tr>
            <td colspan="4"></td>
        </tr>
        <tr>
            <td id="toAlign" colspan="4">
                <img src="http://www.marietta.edu/News/images/Wikipedia-logo-small.gif" />
                <img src="http://luc.devroye.org/PhilippPoll-Wikipedia-logo-LinuxLibertine--Small.png" />
                <img src="http://2.bp.blogspot.com/-CycORET_pXw/TjFcj6r-RoI/AAAAAAAAGLE/fyM10hArlBE/s1600/wikipedia_logo+SMALL.jpg" />
            </td>
        </tr>
        <tr>
            <td colspan="4"></td>
        </tr>
        <tr>
            <td>eeeeeeeeeeee</td>
            <td>ffffffffffff</td>
            <td>gggggggggggg</td>
            <td>hhhhhhhhhhhh</td>
        </tr>
    </table>
</body>

我的CSS是:

table {
    margin: 0 auto;
    font-family: "Courier New";
}

#toAlign {
    text-align: center;
    vertical-align: middle;
}

1 个答案:

答案 0 :(得分:3)

http://jsfiddle.net/sDLxt/1/

vertical-align: middle;应用于<img>

#toAlign img {
    vertical-align: middle;
}