dto5637 2019-05-15 00:42
浏览 111
已采纳

Laravel if语句用于更改样式的各种编号项

I have a gallery of products laid out like this:

gallery of products

<div class="row no-gutters bg-light">
                @foreach ($products as $product)
                <!-- Column 1 -->
                <div class="col-6 @if(count($products) === 1 || 4 || 5) card-w-bg @endif">
                    <div class="row no-gutters">
                        <!-- Column 1-a --> 
                        <div class="col-6 showcase-col">
                            <div class="overlay"></div>
                            <div class="showcase-hero showcase-text">
                                <h2 class="card-title mb-4"><a href="">{{ $product->name }}</a></h2>
                                <h3 class="card-subtitle text-muted">{{ $product->details }}</h3>
                                <h4 class="mb-3">{{ $product->presentPrice() }}</h4>
                                <p class="card-text mb-4 d-none d-md-block">Lorem ipsum dolor sit amet consectetur adipisicing elit. A

The if statement needs to add the dark gray bg to items 1, 4 and 5 only.

  • 写回答

3条回答 默认 最新

  • dqpciw9742 2019-05-15 00:53
    关注

    If 1,4 and 5 are the products ids you can:

    @if($product->id === 1 || $product->id === 4 || $product->id === 5) card-w-bg @endif
    

    If 1,4 and 5 are the place in the loop:

    @if($loop->iteration === 1 || $loop->iteration === 4 || $loop->iteration === 5) card-w-bg @endif
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 关于无人驾驶的航向角
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了