有没有办法在CSS或CSS3中切换表/网格中行的颜色?
<table>
<thead>
<tr>
<td>Name</td>
<td>Votes</td>
</tr>
</thead>
<tbody class="rows">
<tr>
<td>Barack Obama</td>
<td>50%</td>
</tr>
<tr>
<td>Mitt Romney</td>
<td>48%</td>
</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
例如,奇数行是白色,偶数行是蓝色.
.rows tr:odd
{
background-color: White
}
.rows tr:even
{
background-color: blue
}
或者那是不可能的?
我想知道是否有办法找到对象是数组还是IEnumerable,它比这更漂亮:
var arrayFoo = new int[] { 1, 2, 3 };
var testArray = IsArray(arrayFoo);
// return true
var testArray2 = IsIEnumerable(arrayFoo);
// return false
var listFoo = new List<int> { 1, 2, 3 };
var testList = IsArray(listFoo);
// return false
var testList2 = IsIEnumerable(listFoo);
// return true
private bool IsArray(object obj)
{
Type arrayType = obj.GetType().GetElementType();
return arrayType != null;
}
private bool IsIEnumerable(object obj)
{
Type ienumerableType = obj.GetType().GetGenericArguments().FirstOrDefault();
return ienumerableType != null;
}
Run Code Online (Sandbox Code Playgroud)