html - 带有另一个表的表列

标签 html css angularjs html-table

我必须制作一个表格,其中一列有另一个表格,但我希望每个交替行的颜色不同。图像如下:(再次忽略字符列) sample image

请在下面找到 angularJS 示例表代码:(列表可以包含任意数量的元素,即偶数或奇数)

<table style="border: 1px solid;">
<thead>
  <th>Character</th>
  <th>Name</th>
  <th>CharacterAgain</th>
</thead>
<tbody>
           <tr ng-repeat="actor in AAA.cast">
            <td>{{actor.character}}</td>
<td>
  <table>
   <tr ng-repeat="actor1 in AAA.cast"> // could be some another list
      <td>
     {{actor.name}}
     </td>

   </tr>
  </table>
</td>
</tr>
</tbody>
</table>

我已经尝试了很多替代方法来通过脚本分配 CSS 类,但在一种或另一种情况下它们都失败了。如果有人可以为此给我工作 jsFiddle,我将非常感激。请让我知道这是否可以通过 CSS 实现。

最佳答案

很简单,在你的css文件中添加

tr:nth-child(even) {background: #CCC}
tr:nth-child(odd) {background: #FFF}

示例:http://jsfiddle.net/x8vxhuhk/

如果您需要确保这只发生在内表上,您可以向整个表添加一个类,即

HTML:

<table class='striped'>

CSS:

.striped tr:nth-child(even) {background: #CCC}
.striped tr:nth-child(odd) {background: #FFF}

或者,如果您无权更改类,则可能会有些困惑,例如:

CSS:

table table tr:nth-child(even) {background: #CCC}
table table tr:nth-child(odd) {background: #FFF}

支持非常好,唯一的问号是 IE8 http://caniuse.com/#feat=css-sel3

编辑

所以,你可以这样做:

/* Outer table */
table tr:nth-child(even) {background: #FFF}
table tr:nth-child(odd) {background: #CCC}
/* Inner table */
table table tr:nth-child(even) {background: #CCC}
table table tr:nth-child(odd) {background: #FFF}

关于html - 带有另一个表的表列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27769816/

相关文章:

javascript - 可降级链接 - Ajax 内容的 SEO

html - 背景颜色和背景图像在 IE 和 Mozilla Firefox 中打印为 PDF 时不显示

javascript - angularjs日期时区调整问题

css - 单击另一个 Accordion 中的链接时 Accordion 图像不会更改

javascript - 如何使用 jQuery 获取在 css 中设置的宽度值

CSS 下拉菜单 : how do I click on the whole li:hover, 不就是里面的超链接吗?

jquery - 检索设置为 "cover"的背景图像的大小

javascript - 将 AngularJS 迁移到 Angular 4,5(带 DEMO)

tdd - 正确测试附加到 $scope 的 promise

html - 使用 CSS 限制每行的字符数