У меня есть шаблон по умолчанию, который выглядит так
когда я добавляю свой цикл, он становится таким
Как вы видите, на втором изображении заполнение и поля не такие же, как по умолчанию, но вывод html выглядит нормально
<div class = "col-md-5 col-xs-12 pad-l">
<div class = "row">
@foreach($featuresTwo as $featuret)
@if ($loop->first)
<div class = "col-sm-12">
<div class = "post-overaly-style hot-post-top clearfix">
<div class = "post-thumb">
<a href = "#">
<img class = "img-fluid" src = "theme/images/news/tech/gadget2.jpg" alt = "" />
</a>
</div>
<div class = "post-content">
<a class = "post-cat" href = "#">
@foreach($featuret->categories as $categoryt)
{{ $loop->first ? ' ' : ', ' }}
{{$categoryt->title}}
@endforeach
</a>
<h2 class = "post-title title-large">
<a href = "#">{{$featuret->title}}</a>
</h2>
</div><!-- Post content end -->
</div><!-- Post Overaly end -->
</div><!-- Col end -->
@else
<div class = "col-sm-6 pad-r-small">
<div class = "post-overaly-style hot-post-bottom clearfix">
<div class = "post-thumb">
<a href = "#"><img class = "img-fluid" src = "theme/images/news/lifestyle/travel2.jpg" alt = "" /></a>
</div>
<div class = "post-content">
<a class = "post-cat" href = "#">
@foreach($featuret->categories as $categoryt)
{{ $loop->first ? ' ' : ', ' }}
{{$categoryt->title}}
@endforeach
</a>
<h2 class = "post-title title-medium">
<a href = "#">{{$featuret->title}}</a>
</h2>
</div><!-- Post content end -->
</div><!-- Post Overaly end -->
</div><!-- Col end -->
@endif
@endforeach
</div>
</div><!-- Col 5 end -->
Где я ошибся? Как это исправить?
Спасибо.
исходный HTML без цикла
<div class = "col-md-5 col-xs-12 pad-l">
<div class = "row">
<div class = "col-sm-12">
<div class = "post-overaly-style hot-post-top clearfix">
<div class = "post-thumb">
<a href = "#">
<img class = "img-fluid" src = "images/news/tech/gadget2.jpg" alt = "" />
</a>
</div>
<div class = "post-content">
<a class = "post-cat" href = "#">Gadget</a>
<h2 class = "post-title title-large">
<a href = "#">Samsung Gear S3 review: A whimper, when smartwatches need a bang</a>
</h2>
</div><!-- Post content end -->
</div><!-- Post Overaly end -->
</div><!-- Col end -->
<div class = "col-sm-6 pad-r-small">
<div class = "post-overaly-style hot-post-bottom clearfix">
<div class = "post-thumb">
<a href = "#"><img class = "img-fluid" src = "images/news/lifestyle/travel2.jpg" alt = "" /></a>
</div>
<div class = "post-content">
<a class = "post-cat" href = "#">Travel</a>
<h2 class = "post-title title-medium">
<a href = "#">Early tourists choices to the sea of Maldiv…</a>
</h2>
</div><!-- Post content end -->
</div><!-- Post Overaly end -->
</div><!-- Col end -->
<div class = "col-sm-6 pad-l-small">
<div class = "post-overaly-style hot-post-bottom clearfix">
<div class = "post-thumb">
<a href = "#"><img class = "img-fluid" src = "images/news/lifestyle/health1.jpg" alt = "" /></a>
</div>
<div class = "post-content">
<a class = "post-cat" href = "#">Health</a>
<h2 class = "post-title title-medium">
<a href = "#">That wearable on your wrist could soon...</a>
</h2>
</div><!-- Post content end -->
</div><!-- Post Overaly end -->
</div><!-- Col end -->
</div>
</div><!-- Col 5 end -->
.................................................. .................................................. ....................
@wheelmaker, да, я обновлю свой вопрос.
@wheelmaker обновлен






Исходный код для двух столбцов половинной ширины имеет такой:
<div class = "col-sm-6 pad-r-small">
И такой:
<div class = "col-sm-6 pad-l-small">
Но вы использовали цикл для создания двух таких же:
<div class = "col-sm-6 pad-r-small">
Вероятно, вам следует просто указать функции в массиве $featuresTwo и отбросить циклы, чтобы вы могли точно воспроизвести код.
Вы, конечно, можете отслеживать, где вы находитесь в цикле, и соответствующим образом изменять класс, но я думаю, что это пример чрезмерного усложнения вещей, чтобы избежать любого количества дублирования, и будет только усложняться, если / когда эти div требуются дальнейшие изменения.
спасибо человек, у меня есть идея, но я сделал это по-другому, и теперь это исправлено :-D
Принял ваш ответ и опубликовал решение;)
Основываясь на ответе wheelmaker, я получил идею и изменил свой div после @else, чтобы он был похож
@if ($loop->last)
<div class = "col-sm-6 pad-l-small">
@else
<div class = "col-sm-6 pad-r-small">
@endif
и это решило проблему стиля.
PS: I'm accepting
wheelmakeranswer because he made me realized the issue.
у вас есть оригинальный html без циклов для сравнения?