Css :last-child using on Laravel @foreach

foreach last item php
laravel foreach first item
laravel blade foreach key value
for loop in laravel blade file
laravel blade get first element of array
how to know last item in foreach c#
laravel if last in foreach
laravel last item in foreach

On Laravel blade I'm using this code to iterate through a list which is filled by an array:

<ul>
    @foreach($prerequisites as $prerequisite)
        <li class="pre-course"
            style="border-bottom: 1px solid #eee;">
            <p>
                ...
            </p>
        </li>
    @endforeach
</ul>

on this my code each <li> have border-bottom: 1px solid #eee; and i'm trying to remove that on last child with Css by code:

ul li.pre-course:last-child {
  border-bottom:none;
}

but it doesn't work and last child have border

I suppose that's due to the inline style overriding the stylesheet CSS. Try to move the "regular" rule from inline to the stylesheet, like this:

<ul>
    @foreach($prerequisites as $prerequisite)
        <li class="pre-course">
            <p>
                ...
            </p>
        </li>
    @endforeach
</ul>

and CSS:

ul li.pre-course {
  border-bottom: 1px solid #eee;
}
ul li.pre-course:last-child {
  border-bottom:none;
}

That way :last-child will overwrite the regular CSS rule

How do I remove the last <hr> tag in a foreach loop in Laravel , @php $posts_count = $posts->count(); @endphp @foreach($posts as $key => $​post) <div Another possibility is to use last-child with CSS. Do you want to have parent child level relationship into your laravel project? then you are at right place this tutorial will give you everything you need to build parent child Recursive Relationship in Laravel using Eloquent HasMany Relationship method. Recommended – How to Implement Laravel Eloquent One-to-Many Relationship

ul li:last-child {
  border-bottom:none !important;
}

Blade Foreach: first/last item of the array, So the trick here is that we can use pretty much any core PHP function end($​array) – advances array's internal pointer to the last element, and Similar example – what if we want to add a CSS class to the last menu item? Laravel 7 is just released by tomorrow, Laravel 7 gives several new features and LTS support. So if you are new to laravel then this tutorial will help you create insert update delete application in laravel 7. You just need to follow few step and you will get basic crud stuff using controller, model, route, bootstrap 4 and blade..

Priority of in-line css is higher

    <li class="pre-course">
        <p>
            ...
        </p>
    </li>

Try this css

 ul li.pre-course:not(:last-child) {
     border-bottom: 1px solid #eee;
 }

In a foreach loop, how do I target the last item in the loop , You can try this : foreach( $pages as $key => $post ). and : <div class = "event <?​php if( $key == ( count( $pages ) - 1 ) ) echo 'last'; ?>" > It will add a last class to  Blade templates are mostly for viewing data. But sometimes we do need to add some checks and IF-structures. One of the tricky examples – loop through @foreach but do some action only on first/last element of the array.

:last-child, Beginning with Selectors Level 4, this is no longer required. Syntax. :last-child. Example. Basic example. HTML. <div> <p>This text isn  Hii Guys, Today, I will explain how can create dynamic multi level menu in laravel we will create example of multi level dynamic menu in laravel you can easy to make many level dynamic menu in laravel. i will show parents and child menu with nested tree view structure in Laravel application.

Determine the first and last iteration in a foreach loop in PHP , How to Upload Image into Database and Display it using PHP ? is an inbuilt function in PHP which takes array name as argument and returns its last element. CSS | animation-iteration-count Property · Performance of for vs foreach in PHP​  Great stuff to get data about loop. There is always a hustle to establish inside-of-the loop position. Loop Variable gives you that on a golden platter … and much more.

How to Create Multi Level Dynamic Menu In Laravel Treeview, laravel 7/6 dynamic dropdown menu ,how to create dynamic treeview menu , laravel 7/6 tree I use jquery for make tree view layout and child relationship with menu model for hierarchical data. @foreach($menus as $menu) In last step, we have to add one css file and one js file for treeview design. Blade is the simple, yet powerful templating engine provided with Laravel. Unlike other popular PHP templating engines, Blade does not restrict you from using plain PHP code in your views. In fact, all Blade views are compiled into plain PHP code and cached until they are modified, meaning Blade adds essentially zero overhead to your application.

Comments
  • Remove the inline style-tag in the element and set that border in your CSS-file instead. If you, for some strange reason, don't want to do that, try and change your css to: border-bottom:none !important;. Inline styles takes precedence over CSS, which is one of several reasons not to use them.
  • @MagnusEriksson Thanks problem resolved