设置<;td>;在刀刃模板中的@if中


Set Background Color of a <td> in a @if in Blade Templating

我有一个这样的表格单元格:

<td>
    @if ($user->status == 1)Present
    @elseif ($user->status_detail != null) Absent(see Details)
    @else Absent
    @endif
</td>

所以我的问题是,我不想只给表格单元格一个单词"Present",我还想给它一个颜色。你们对这个问题有什么建议吗?

您需要在元素中添加此项,如下例所示

<td class="
@if ($user->status == 1)
present
@else
absent
@endif
">
    @if ($user->status == 1)Present
    @elseif ($user->status_detail != null) Absent(see Details)
    @else Absent
    @endif
</td>

然后在CSS中,你可以定义你想要的样式,例如:

.present {background:#0f0;}
.absent {background:#f00;}

在文本"Present"周围加一个标签。然后给span指定一个类,使用CSS给span指定背景颜色。

<td>
    @if ($user->status == 1)<span class="present">Present</span>
    @elseif ($user->status_detail != null) Absent(see Details)
    @else <span class="absent">Absent</span>
    @endif
</td>

在CSS 中

.present{ background:#ff0;display:block; width:100%;}
.absent{ background:#f00;display:block; width:100%;}
@if ($user->status == 1) 
   $status = Present;
   $color = "green";
@elseif ($user->status_detail != null) 
   $status = Absent(see Details);
   $color = "red"
@else
   $status = Absent(see Details);
   $color = "red";
@endif
<td style="background-color:{{$color}}">{{$status}}</td>
<td class="status">
@if ($user->status == 1)Present
@elseif ($user->status_detail != null) Absent(see Details)
@else Absent
@endif
</td>

CSS

.status{background:#fff;}

还是缺席或在场时应该有所不同?