如何为动态生成的元素创建不同的CSS?

时间:2015-04-15 19:33:43

标签: html css

如何为动态生成的元素生成不同的CSS?

我的问题在于:我们有一个日期选择器小部件,其中生成了表th个元素,其中text-align:left。当它离开时,th向左对齐,但右侧>>在一起。当我将它们对齐时,会出现相反的问题。我需要做的是将align left应用于第一个<<align right到最后一个>>。但这些项目是动态生成的。正在使用SCSS规则。

th { text-align: left }

enter image description here

th {text-align: right }

enter image description here


日期选择器的每一段,&lt;&lt;,2007年6月,&gt;&gt;在th内的tr不同:

enter image description here

enter image description here

2 个答案:

答案 0 :(得分:5)

请参阅:first-child:last-child伪类:

th:first-child { text-align: left; }
th:last-child { text-align: right; }

答案 1 :(得分:0)

可以将 text-align:center 设置为所有元素。但它可能就是你想要的。