Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/475.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在第一次tr的特定td上应用css_Javascript_Html_Css_Angularjs - Fatal编程技术网

Javascript 如何在第一次tr的特定td上应用css

Javascript 如何在第一次tr的特定td上应用css,javascript,html,css,angularjs,Javascript,Html,Css,Angularjs,我是AngularJS的初学者,我真的不想用JQuery来解决我的问题(也许我错了) 我的问题是: 我想对表中第一个tr中的最后一个td元素应用CSS 我的代码: {{person.name} {{person.email} 因此,对于第一个tr,最后一个td元素应该是{{person.email} 谢谢你的回答和解释 编辑:我忘了说,我知道如何通过在最后一个td上应用css来解决我的问题,但我想用angularjs来解决,因为我可以有不同的人,这取决于不同,我想应用另一种CSS样式。或者,

我是AngularJS的初学者,我真的不想用JQuery来解决我的问题(也许我错了)

我的问题是:

我想对表中第一个tr中的最后一个td元素应用CSS

我的代码:


{{person.name}
{{person.email}
因此,对于第一个tr,最后一个td元素应该是
{{person.email}

谢谢你的回答和解释


编辑:我忘了说,我知道如何通过在最后一个td上应用css来解决我的问题,但我想用angularjs来解决,因为我可以有不同的人,这取决于不同,我想应用另一种CSS样式。

或者,如果您不想放置id或类,可以这样做:

table tr:first-child td:last-child {}
请注意,并非所有浏览器都支持子选择器

使用伪类-

.TABLE-CLASS tr:first-child td:last-child{
   //style
}
:first-child伪类表示“如果此元素是其父元素的第一个子元素”last child表示“如果此元素是其父元素的最后一个子元素”。注意,只有元素节点(HTML标记)计数,这些伪类忽略文本节点。 所以这些风格适合你-

table tr td:last-child{
}

table tr td:first-child{

}

如果每行只有2个
,您可以使用CSS
+
选择器绕过IE8中缺少对
:last child
支持的问题:

table tr:first-child td + td {
  /* styles */
}

这将选择前面有另一个
的任何
,并且是每个
的第一个
的子级
使用angular的
ng class
指令有条件地应用样式:

<table>
    <tr ng-repeat="person in persons | orderBy:'name'">
        <td>{{person.name}}</td>
        <td ng-class="{'myClass':$index==0}">{{person.email}}</td>
    </tr>
</table>    

{{person.name}
{{person.email}