尝试在HAML中创建一个表,我有以下内容:
%table
%tbody
%tr
%th{:rowspan => 2} Name
%th{:class => "leftBorderS", :colspan => 5} Monday
%th{:class => "leftBorderS", :colspan => 5} Tuesday
%th{:class => "leftBorderS", :colspan => 5} Wednesday
%th{:class => "leftBorderS", :colspan => 5} Thursday
%th{:class => "leftBorderS", :colspan => 5} Friday
%th{:class => "leftBorderS", :colspan => 5} Saturday
%tr
- 6.times do
%th{:class => "leftBorderS"} A
%th{:class => "leftBorderD"} B
%th{:class => "leftBorderD"} C
%th{:class => "leftBorderD"} D
%th{:class => "leftBorderD"} E
- @data.each do |row|
%tr
- row.each do |column|
%td{:class => "leftBorderD"}= column
Css课程:
table {
border-collapse: collapse;
}
th {
border: 1px solid #ccc;
padding: 0.2em;
}
.weeklyReview .leftBorderS {
border-left: 1px solid black;
text-align: center;
}
.weeklyReview .leftBorderD {
border-left: 1px dotted orange;
}
.weeklyReview .rowGray {
background-color: gray;
}
.weeklyReview .rowWhite {
background-color: white;
}
Rails控制器传递的示例数据:
@data = [["adam", 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5], ["boy", 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5], ["charles", 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5], ["david", 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5], ["echo", 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5], ["foxtro", 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5], ["gamma", 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5], ["helio", 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5], ["indigo", 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5],]
问题出现在代码的最后部分。我希望每个其他%tr
的颜色都不同。目前默认为灰色,但这仍然意味着其他每个都必须是白色的,所以我只做了两个类来切换两个类)。另外,为了分隔天数,只有某些%td
s具有实线左边框,否则它们将具有虚线边框。
对于HAML标记:
答案 0 :(得分:4)
这似乎是一个CSS问题。
使用nth-of-type
并忘记所有额外的课程:
table {
background-color: salmon;
}
th {
background: salmon;
}
tr:nth-of-type(2n) {
background: salmon;
}
tr:nth-of-type(2n+1) {
background: lightblue;
}
您也可以使用列:
td:nth-of-type(5n-3) {
color: white
}