1

如何使用 css 实现以下功能(背景颜色与标题行重叠的背景图像): 在此处输入图像描述

这是表格中 TH 单元格的一部分。TH 行将是颜色 #0098da 并且在 TH 单元格的末尾将是图像(图像的 url 在这里http://tax.allfaces.lv/templates/tax/images/pg_arrow.png)。

我试图在 TH 中使用 bg 图像定位 div,但我遇到了图像应该与 TH 边界重叠的问题。结果我得到了以下信息:

在此处输入图像描述

HTML:

    <table id="duration-of-refund" border="0">
    <tbody>
        <tr>
            <th>
                <p>Purchases in Webshops</p>
                <div class="img-at">&nbsp;</div>
            </th>
            <th>
                <p>Currency conversion, Refund transfer</p>
                <div class="img-arrow">&nbsp;</div>
            </th>
        </tr>
        <tr>
            <td>
                <p>Some text here Some text here Some text here Some text here Some text here</p>
            </td>
            <td>
                <p>Some text here Some text here Some text here Some text here Some text here</p>
            </td>
        </tr>
    </tbody>
</table>

CSS:

    #duration-of-refund td {
     width: 400px;
 }
 #duration-of-refund th {
     font-size: 21px;
     color: white;
     text-align: left;
     height: 84px;
     max-height: 84px;
 }
 #duration-of-refund tr th:nth-child(1) {
     background-color: #0098da;
 }
 #duration-of-refund tr th:nth-child(2) {
     background-color: #1F5CA9;
 }
 #duration-of-refund tr th:nth-child(1) p, #duration-of-refund tr th:nth-child(2) p {
     width: 190px;
     float: left;
 }
 .img-at, .img-arrow {
     width: 83px;
     height: 84px;
     float: right;
     margin-right: 20px;
     position: relative;
     top: -20px;
 }
 .img-arrow {
     background-image: url(http://tax.allfaces.lv/templates/tax/images/pg_arrow.png);
 }
 .img-at {
     background-image: url(http://tax.allfaces.lv/templates/tax/images/pg_at.png);
 }
 #duration-of-refund tr td:nth-child(2) {
     background-color: #cceaf8;
 }
}

JSfiddle 示例:http: //jsfiddle.net/rAVqx/

我认为,应该有另一种方法来做到这一点。

请给我一些线索如何实现这一目标?我还有其他具有不同图像的 TH 细胞以相同的方式定位。

4

1 回答 1

0

试试这个将图像类标签放在另一个 div 中并将样式应用为

 float:right;margin-right:90px

并将图像位置作为绝对

 position: absolute;

您的代码刚刚修改

HTML

<table id="duration-of-refund" border="0">
    <tbody>
        <tr>
            <th>
                <p>Purchases in Webshops</p>
                <div style="float:right;margin-right:90px;">
                <div class="img-at">&nbsp;</div>
                </div>
            </th>
            <th>
                <p>Currency conversion, Refund transfer</p>
                <div style="float:right;margin-right:90px;">
                <div class="img-arrow">&nbsp;</div>
                </div>
            </th>
        </tr>
        <tr>
            <td>
                <p>Some text here Some text here Some text here Some text here Some text here</p>
            </td>
            <td>
                <p>Some text here Some text here Some text here Some text here Some text here</p>
            </td>
        </tr>
    </tbody>
</table>

CSS:

#duration-of-refund td {
     width: 400px;
 }
 #duration-of-refund th {
     font-size: 21px;
     color: white;
     text-align: left;
     height: 84px;
     max-height: 84px;
 }
 #duration-of-refund tr th:nth-child(1) {
     background-color: #0098da;
 }
 #duration-of-refund tr th:nth-child(2) {
     background-color: #1F5CA9;
 }
 #duration-of-refund tr th:nth-child(1) p, #duration-of-refund tr th:nth-child(2) p {
     width: 190px;
     float: left;
 }
 .img-at, .img-arrow {
     width: 83px;
     height: 84px;
     float: right;
     margin-right: 20px;
     position: absolute;
     top: -20px;
 }
 .img-arrow {
     background-image: url(http://tax.allfaces.lv/templates/tax/images/pg_arrow.png);
 }
 .img-at {
     background-image: url(http://tax.allfaces.lv/templates/tax/images/pg_at.png);
 }
 #duration-of-refund tr td:nth-child(2) {
     background-color: #cceaf8;
 }
}
于 2013-06-10T08:27:28.763 回答