2

Laravel の Blade ビューに次のコードがあります。

@foreach ($questions as $question)
<div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
  @if(isset($question->task))
   <a href="{{URL::action('showTask', $question->task_id)}}"><h4> <span class='glyphicon glyphicon-file'></span> {{$question->Task->name}}</h4></a>
  @endif

  
  <blockquote >
    <a class="nostyle" href="{{URL::action('showQuestion',$question->id)}}" ><p

        @if($question->status==1)
          class="text-success"
        @endif
      >{{$question->text}}</p></a>
  <footer>Gevraagd door <strong>{{$question->Author->getFullName('mij') }}</strong> op <strong>{{DateConverter::dateToString($question->created_at)}}</strong></footer>
  
  @if($question->status==1)
    <span class="label label-success">Beantwoord</span>
  @endif 
</blockquote>

</div>
  @endforeach

すべての質問を表示しています。それらを3 の素敵な行に表示したい. ただし、一部のテキスト ( $question->text ) は他のテキストよりも長いため、常に完全に新しい行を開始するとは限りませんが、スクリーンショットでわかるように、以前の最も短いグリッドに追加されます。

ここに画像の説明を入力

私が望むのは、テーブル、3 つの列、そして 3 つの新しいアイテムを含む同じ高さの新しい行のようなものです。

だから私は方法を探しています

  • すべての列を同じ高さで返す

  • または、3 つの列ごとに行 div を自動的に追加して閉じます。

    これを行う最良の方法は何ですか?

4

1 に答える 1

13

次のようなことを試すことができます:

@foreach(array_chunk($questions->all(), 3) as $threeQuestions)
    <div class="row">
        @foreach($threeQuestions as $question)
            // Do everything here
            @if(isset($question->task))
                <a href="{{URL::action('showTask', $question->task_id)}}"><h4> <span class='glyphicon glyphicon-file'></span> {{$question->Task->name}}</h4></a>
            @endif

            // ...

        @endforeach
    </div>
@endforeach

ここでは、$threeQuestions反復ごとに 3 つの項目が含まれているため、次.rowのように 3 つの項目をそれぞれ保持しますdiv

<div class='row'>
    item-1
    item-2
    item-3
</div>
<div class='row'>
    item-4
    item-5
    item-6
</div>
于 2014-03-16T01:21:23.000 に答える