html - 如何将图像对齐到行的顶部?

标签 html css

我试图将图像对齐到此表中行的顶部:

<table class="customers">
    <thead>
    <tr>
        <th  class="first">
            How can I get the images aligned to the top of the row?
        </th>
        <th class="second"></th>
        <th class="third"></th>
        <th class="fourth ng-binding">Mary</th>
        <th ng-class="persons.length>1 ? 'fifth' : (persons.length<2 ? 'fifth_single' : '') " class="ng-binding fifth">

        </th>
    </tr>
    </thead>
    <tbody>
    <tr ng-class="'odd'" class="odd border_bottom">
        <td>
            <table class="docInfo">
                <tbody>
                <tr>
                    <td rowspan="2" ng-show="showDocInfo(1,strategy.statuses[0].reason)" ng-click="showTextArea(1)"
                        class="ng-hide"><img src="http://cdn.mysitemyway.com/etc-mysitemyway/icons/legacy-previews/icons-256/3d-transparent-glass-icons-business/076004-3d-transparent-glass-icon-business-document4.png" alt="docimage"></td>
                    <td ng-show="showDocInfo(1,strategy.statuses[0].reason)" class="ng-binding ng-hide">Mary</td>
                </tr>
                <tr>
                    <td ng-show="showDocInfo(1,strategy.statuses[0].reason)" class="ng-hide"><span><p
                            class="ng-binding">Mar
                        4, 2015 2:42:25 PM</p></span></td>
                </tr>
                </tbody>
            </table>

            <table class="docInfo">
                <tbody>
                <tr>
                    <td rowspan="2" ng-show="showDocInfo(1,strategy.statuses[0].reason)" ng-click="showTextArea(1)"
                        class="ng-hide"><img src="http://cdn.mysitemyway.com/etc-mysitemyway/icons/legacy-previews/icons-256/3d-transparent-glass-icons-business/076004-3d-transparent-glass-icon-business-document4.png" alt="docimage"></td>
                    <td ng-show="showDocInfo(1,strategy.statuses[0].reason)" class="ng-binding ng-hide">Mary</td>
                </tr>
                <tr>
                    <td ng-show="showDocInfo(1,strategy.statuses[0].reason)" class="ng-hide"><span><p
                            class="ng-binding">Mar
                        4, 2015 2:42:25 PM</p></span></td>
                </tr>
                </tbody>
            </table>
        </td>
    </tr>
    <tr ng-class="'odd'" class="odd borderbottom">
        <td>
            <table class="docInfo">
                <tbody>
                <tr>
                    <td rowspan="2" ng-show="showDocInfo(1,strategy.statuses[0].reason)" ng-click="showTextArea(1)"
                        class="ng-hide"><img src="http://cdn.mysitemyway.com/etc-mysitemyway/icons/legacy-previews/icons-256/3d-transparent-glass-icons-business/076004-3d-transparent-glass-icon-business-document4.png" alt="docimage"></td>
                    <td ng-show="showDocInfo(1,strategy.statuses[0].reason)" class="ng-binding ng-hide">Mary</td>
                </tr>
                <tr>
                    <td ng-show="showDocInfo(1,strategy.statuses[0].reason)" class="ng-hide"><span><p
                            class="ng-binding">Mar
                        4, 2015 2:42:25 PM</p></span></td>
                </tr>
                </tbody>
            </table>

            <table class="docInfo">
                <tbody>
                <tr>
                    <td rowspan="2" ng-show="showDocInfo(1,strategy.statuses[0].reason)" ng-click="showTextArea(1)"
                        class="ng-hide"><img src="http://cdn.mysitemyway.com/etc-mysitemyway/icons/legacy-previews/icons-256/3d-transparent-glass-icons-business/076004-3d-transparent-glass-icon-business-document4.png" alt="docimage"></td>
                    <td ng-show="showDocInfo(1,strategy.statuses[0].reason)" class="ng-binding ng-hide">Mary</td>
                </tr>
                <tr>
                    <td ng-show="showDocInfo(1,strategy.statuses[0].reason)" class="ng-hide"><span><p
                            class="ng-binding">Mar
                        4, 2015 2:42:25 PM</p></span></td>
                </tr>
                </tbody>
            </table>
        </td>
    </tr>
    <tr ng-class="'even'" class="even">
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td>
        </td>
    </tr>
    <tr ng-class="'odd'" class="odd">
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td>
        </td>
    </tr>
    <tr ng-class="'even'" class="even">
        <td></td>
        <td></td>
        <td></td>
        <td>
        </td>
        <td>
        </td>
    </tr>
    </tbody>
</table>

目前,图像有点位于每一行的中间。我怎样才能让它们与行的顶部对齐?我尝试设置 verticalalign 属性,但没有修复它。

这是样式表:

.customers
{
    table-layout: fixed;
    border: in 2px;
    float: left;
}

img
{
    height:30px;}

.customers tr.border_bottom > td {
    border-bottom:1pt solid black;
}

.customers td {
    margin: 0 5px;
    padding: 10px 8px;
    line-height: 1.4;
    vertical-align: middle;
}

td {
    vertical-align: top;
}
.customers .first {
    width: 40%;
}

.customers .first_single {
    width: 39%;
}

.customers .second {
    width: 20%;
}

.customers .third {
    width: 20%;
}
.customers .fourth {
    width: 20%;
}
.customers .fifth{
    width: 20%;
}

.customers .fifth_single{
    width: 1%;
}

tr.odd>td,tr.even>td{
    width:100%;
}

.docInfo {
    table-layout: fixed;
    float: left;
}

.docInfo td {
    margin: 0 5px;
    padding: 0px 5px;
    line-height: 0.2;
    font-size: 10px;
    vertical-align: top;
    font-family: Arial;
    font-weight: bold;
}


.first {
    width: 40%;
}

.second {
    width: 60%
}

img {
    background: transparent;
    height: 25px;
}

}

还创建了一个 plunkr 网址:http://plnkr.co/edit/CssSPt?p=preview

最佳答案

我觉得你的问题是

行高:0.2;

应用于 .docInfo td 的样式 对于文本来说行高不够大,因此会导致表格未对齐。

取消此样式,图像的对齐方式将移动到顶部。

如果您的文本需要此行高,请将其应用于段落而不是表格单元格。

关于html - 如何将图像对齐到行的顶部?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28868893/

相关文章:

html - 滑动动画文字颜色变化

javascript - 如何在保持鼠标悬停功能的同时使图像居中

python - 在 Beautifulsoup 中的某个点后删除 html

jquery - 带有声音和设置 cookie 的按钮点击动画

javascript - Polymer()中的回调;当显示元素时

javascript - 我的 css 动画消耗了大量资源

php - 为什么两个页面,100% 相同的代码,都包含相同的 style.css 却有不同的输出?

html - 使用两个背景图像时的 CSS 属性

css - 内容溢出时展开div

html - 与 Flexbox 相同的宽度