html - 如何将背景图像设置为具有 colspan 的表格单元格?

标签 html css

我使用 css 为单元格设置背景,但它不适用于整个单元格。

我正在尝试将背景图像设置为第一个和最后一个 <TR> , 但它是这样显示的。

我正在尝试申请 .first第一个和最后一个类属性 <tr> .我应该怎么做才能使其适用于 TR?

 <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <style type="text/css">

 .excel{
         background:url(smallimage/excel.jpg);
          background-size:24px 24px;
          background-repeat:no-repeat;
          position: relative;
           margin:3px;
           left: 2px;
            top: 1px;
        }


        td.yellostar{
        background-image: url(smallimage/yellowstar.jpg);  /* forward slash for the path */
        width: 20px; /* use you own image size; */
        height: 20px; /* use you own image size; */
        background-repeat: no-repeat;
        background-position: center;
        text-align: center;
        vertical-align: top;
        } 
        .first{
        background-image:url(smallimage/trbackgr.jpg);
        background-repeat: repeat-x;
        }

    </style>
    </head>

    <body>
    <table width="95%" border="1" cellspacing="0" cellpadding="0">
        <tr class="first">
        <th colspan="2" class="first">chapter #|chapter Name</th>
        <th>Linkage</th>
        <th>project<br/>count</th>
        <th>Task<br>count</th>
        <th>issues<br> Open/All</th>
        <th>Action</th>

      </tr>
        <tr >
        <td>05</td>
        <td><div class="excel" > &nbsp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp<u>Chapter 5:Data of Information</div></td>
        <td class="yellostar" ></td>
        <td><p align="center">3</p></td>
        <td><p align="center">21</p>
        </td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>06</td>
        <td><div class="excel">&nbsp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp<u>Chapter 6:Data Tabels and Amortization Tabels</div></td>
        <td class="yellostar">&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>07</td>
        <td><div class="excel" >&nbsp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp<u>Chapter 7:Data consolidation,Links and Formula Auditing</div></td>
        <td class="yellostar">&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>08</td>
        <td><div class="excel" >&nbsp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp<u></td>
        <td class="yellostar">&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>09</td>
        <td><div class="excel" >&nbsp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp<u></div></td>
        <td class="yellostar">&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>10</td>
        <td><div class="excel" >&nbsp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp<u></div></td>
        <td class="yellostar">&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr class="first">


        <td colspan="7" class="first" >&nbsp;</td>
      </tr>
    </table>
    </body>
    </html>

最佳答案

您可以使用伪类 :first-child:last-child 。 看我的例子:jsfiddle

但是 :last-child 不是跨浏览器的,IE 需要修复。

并且您在为背景指定引用图像时出错 w3schools .

关于html - 如何将背景图像设置为具有 colspan 的表格单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10964089/

相关文章:

javascript - 使用 HTML5 技术操作和上传表单文件数据

html - 在可滚动的 div 内 Canvas 图像

css - 如何移动与某些文本内联的图像的位置?

javascript - 如何显示/隐藏我可以与之交互的图像?

CSS3 背景图像不会垂直拉伸(stretch)

javascript - 为什么我的网站屏幕分辨率与移动设备的屏幕尺寸不匹配?

HTML CSS - 图片不显示?

html - 响应断点后将 Bootstrap 第 3 列移动到行的顶部

javascript - 创建一个非常低特异性的 css 属性

javascript - 如何根据列的宽度换行文本