javascript – 用字符填充表格行中的空白区域

我想使用jQuery将某些字符附加到HTML表行,以便每行填充一定的像素数.我希望能够右对齐或居中对齐列.例如:

Header        Header2     Header3
something.......foo...........baz
another........abcde.........html

解决方法:

你可以在< td>上使用重复的背景图像.标记,然后将文本内容包装在< span>中并设置那些< span>的背景颜色用于匹配其背后的任何标签.

请参阅jsfiddle的工作演示
http://jsfiddle.net/gDtYz/1/

HTML

<table>
  <tr>
      <th>Header</th>
      <th>Header2</th>
      <th>Header3</th>
  </tr>
  <tr>
      <td><span>something</span></td>
      <td><span>foo</span></td>
      <td><span>baz</span></td>
  </tr>
  <tr>
      <td><span>another</span></td>
      <td><span>abcde</span></td>
      <td><span>html</span></td>
  </tr>
</table>

CSS

table {
    width: 350px;
    background: #fff; 
    font-family: sans-serif;
}

th { font-weight: bold; text-align: center; }
td {
    background: transparent 
                url("http://nontalk.s3.amazonaws.com/dots.png") 
                repeat-x 0 75%; 
    height: 14px;
    font-size: 14px;
    vertical-align: bottom;
    text-align: center;
}

td span {
    background: #fff; 
    line-height: 18px;
    height: 18px;
    display: inline-block;
    padding: 0 4px;
}

th:first-child,
td:first-child { text-align: left; }

td:first-child span { padding: 0 4px 0 0; }

th:last-child,
td:last-child { text-align: right; }

td:last-child span { padding: 0 0 0 4px; }

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...