Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为laravel表应用交替行颜色CSS_Php_Css_Laravel_Laravel 5 - Fatal编程技术网

Php 为laravel表应用交替行颜色CSS

Php 为laravel表应用交替行颜色CSS,php,css,laravel,laravel-5,Php,Css,Laravel,Laravel 5,如何在laravel表中应用交替行颜色CSS。我想显示表格行的备用颜色。我把gridview cssclass放在桌子上了。我想将.gridview tr.even td应用于偶数行计数,即倍数为2的行 我的CSS文件 .gridview { font-family: "arial"; background-color: #FFFFFF; width: 100%; font-size: small; } .gridview th { ba

如何在laravel表中应用交替行颜色CSS。我想显示表格行的备用颜色。我把gridview cssclass放在桌子上了。我想将
.gridview tr.even td
应用于偶数行计数,即倍数为2的行

我的CSS文件

.gridview {
    font-family: "arial";
    background-color: #FFFFFF;
    width: 100%;
    font-size: small;
}

    .gridview th {
        background: #0CA3D2;
        padding: 5px;
        font-size: small;
    }

    .gridview td {
        background: #B6E1EE;
        color: #333333;
        font: small "arial";
        padding: 4px;
    }

    .gridview tr.even td {
        background: #FFFFFF;
    }
表代码

<table id="showBooksIn" class="table table-bordered gridview">
            <thead>
                <tr>
                    <th>BOOK ID</th>
                    <th>BILLED DATE</th>                      
                </tr>
            </thead> 
            <tbody>
                @foreach($ordered_books as $data)
                 <tr>
                     <td> {{$data['BookID']}} </td>                         
                     <td> {{$data['BilledDate']}} </td>
                 </tr>
                @endforeach
          </tbody>          
        </table>

书号
账单日期
@foreach($data形式的订购书籍)
{{$data['BookID']}
{{$data['BilledDate']}
@endforeach

书号
账单日期
@foreach($data形式的订购书籍)
{{$data['BookID']}
{{$data['BilledDate']}
@endforeach

这是php的例子,但我认为用js实现这一点的最好方法是使用css。另一种方法是使用模运算符:

@foreach($ordered_books as $i => $data) 
    @php $class = $i ÷ 2 === 0 ? 'even' : 'odd'; @endphp
    <tr class="{{ $class }}"> 
        <td> {{$data['BookID']}} </td>
        <td> {{$data['BilledDate']}} </td> 
    </tr> 
@endforeach
@foreach($i=>$data)
@php$class=$i÷2==0?“偶数“:“奇数”@endphp
{{$data['BookID']}
{{$data['BilledDate']}
@endforeach

如果您只想玩css:

tr:nth-child(even) td {
   background: #FFFFFF;
}
对于单数tr:

tr:nth-child(odd) td {
   background: grey;
}

我添加了更多的解释。如果它只是css,那么可能
。gridview tr:n类型(偶数)td{/*定义*/}
@RamRaider请向我展示代码,如何实现它
。gridview tr:n类型(偶数)td{/*定义*/}
。非常感谢。
tr:nth-child(odd) td {
   background: grey;
}