dongyuying1507 2015-12-07 13:40
浏览 72
已采纳

Html表样式第一行用foreach

I have looked everywhere but couldn't find the right answer.

How can you style a html table, but only the first row. (And if possible als only the first column of the same row)

But now comes the tricky part, I use a foreach with a desc on it. So I retrieve the data from the database and not just have the data already in my table.

Here is what my code looks like:

<table class="table sortable" id="voteResults" name="voteResults">
  <thead>
    <tr>
      <th>Keuze</th>
      <th>Aantal punten</th>
    </tr>
  </thead>

  @foreach($lists as $i => $list)
    <tbody>
      <tr>
        <td>{{ $list->option }}</td>
        <td>{{ $list->points }}</td>
      </tr>
    </tbody>
  @endforeach
</table>

But how can I style only the first column? And if possible give an image or border-color with it. (Basicly every css

I have updated my code a little bit ($i =>), with this, you can easily get the first id of the column. Only the next problem is, I don't know how to style it with an if function.. (if $i === 1 give background-color: red, for example)

  • 写回答

2条回答 默认 最新

  • dpdbu24262 2015-12-07 13:50
    关注

    A CSS-only solution:

    .table tbody:nth-child(2) tr:first-child td:first-child {
      border: 1px solid #cc0000;
    }
    

    selects the first row inside the body, then the first td inside that row.

    https://developer.mozilla.org/en-US/docs/Web/CSS/%3Afirst-child

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 MATLAB yalmip 可转移负荷的简单建模出错,如何解决?
  • ¥15 数学的三元一次方程求解
  • ¥20 iqoo11 如何下载安装工程模式
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?