【问题标题】:Alternate Image/text position in foreach loop dynamic dataforeach 循环动态数据中的备用图像/文本位置
【发布时间】:2018-11-08 02:06:12
【问题描述】:

所以我使用引导程序以平铺格式显示两个数据块,我可以有两个半行。在这种情况下,右侧有一个图像,左侧有一个显示文本和按钮的 div。我打算让偶数行的图像在左边,奇数在右边。因此,基本上图像将始终位于文本的顶部和下方。在每一行中交替的 div 将被镜像。

使用 javascript、blade、php 或 css 我怎样才能达到这种效果?

@foreach ($offers as $offer)
    <div class="offersNew">
    <div class="row row-equal-height">
        <div class="col-md-6 paddedCol6">
            <div class="inner">
                <h2 class="centered marginTop0">{{ $offer->title or 'No title' }}</h2>
                <h3 class="sub-header centered">{{ $offer->sub_header or '' }}</h3>

                <p class="centered">
                    {{ mb_strimwidth(strip_tags($offer->homepage_description), 0, 200, '...') }}
                </p>

                <div class="callToAction">
                    <center>
                    <a href="/offer/{{ $offer->slug or $offer->id }}">
                        <button class="buttonOne"><p class="sub-header line0 margin1 white smallerText">&nbsp;&nbsp;Let&apos;s Go!&nbsp;&nbsp;</p></button>
                    </a>
                    <a href="/offer/{{ $offer->slug or $offer->id }}">
                        <button class="buttonTwo"><p class="sub-header line0 margin1 blue smallerText">Other Offers</p></button>
                    </a>
                    </center>
                </div>

                @if ($offer->countdown == 1)
                    <div class="row countdown" data-timer="{{ $offer->end }}">
                        <h2 class="sub-header centered">
                            <span class="blueText">OFFER END</span>
                            <span class="days">0</span>:
                            <span class="hours">0</span>:
                            <span class="minutes">0</span>:
                            <span id="seconds"></span>
                            <span id="offerEndtime">0</span>
                        </h2>
                    </div>
                @endif

            </div>
        </div>
        <div class="col-md-6 main-background hidden-sm hidden-xs max400" style="background-image:url('{{ $offer->image or '' }}')">

        </div>
    </div>
</div>
@endforeach

【问题讨论】:

    标签: javascript php css laravel-blade


    【解决方案1】:

    添加一个计数变量并使用模数交替。

    $count = 0;
    
    foreach($offers as $offer){
        if($count % 2 == 0){
            // show variation 1
        }else{
            // show variation 2
        }
        $count++;
    }
    

    【讨论】:

      猜你喜欢
      • 2017-04-24
      • 1970-01-01
      • 1970-01-01
      • 2014-12-10
      • 2014-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-15
      • 1970-01-01
      相关资源
      最近更新 更多