What is the best method for deleting the hr element from the final post?

I'm looking to eliminate the final hr tag from the post

Here is the full code snippet with an image:

https://i.sstatic.net/4PpSl.png

HTML code:

  @forelse (auth()->user()->experiences->sortByDesc('subject') as $experience)
                    <div class="col-md-12">
                      <main class="experience" id="post">
                        <span class="button is-danger is-small text-right is-rounded" data-toggle="modal" data-target="#ExperienceDeleteModal{{ $experience->id }}"><i class="far fa-trash-alt"></i></span>
                        <span class="button is-link is-small text-right is-rounded"   data-toggle="modal" data-target="#ExperienceEditModal{{ $experience->id }}"><i class="fas fa-pen"></i></span>
                        <h1>{{$experience->subject}}</h1>
                        <p class="subtitle is-6">{{$experience->experience_desc}}</p>
                        <hr>
                      </main>
                    </div>
                    @include('frontend.profile.experience.edit')
                    @include('frontend.profile.experience.delete')
                @empty
                    <p class="pl-3">لا يوجد خبرات في الوقت الحالي </p>
  @endforelse

I attempted to use this CSS code, but it removes all hr tags:

#post hr:last-child {
   display:none;
} 

Answer №1

If you're looking to revamp your HTML structure, consider the following adjustments I suggest making. First, I've assigned a class to your parent element, "row", and then transferred the "col-md-12" class to the main element.

<div class="row experiences">
    @forelse (auth()->user()->experiences->sortByDesc('subject') as $experience)
      <main class="experience col-md-12">
        <span class="button is-danger is-small text-right is-rounded" data-toggle="modal" data-target="#ExperienceDeleteModal{{ $experience->id }}"><i class="far fa-trash-alt"></i></span>
        <span class="button is-link is-small text-right is-rounded"   data-toggle="modal" data-target="#ExperienceEditModal{{ $experience->id }}"><i class="fas fa-pen"></i></span>
        <h1>{{$experience->subject}}</h1>
        <p class="subtitle is-6">{{$experience->experience_desc}}</p>
        <hr>
      </main>
        @include('frontend.profile.experience.edit')
        @include('frontend.profile.experience.delete')
    @empty
        <p class="pl-3">There are currently no experiences</p>
    @endforelse
</div>

The resulting HTML will somewhat resemble the code below. The CSS utilizes the main element to target the last main within "experiences", locates the hr, and hides it.

.experiences main:last-of-type hr { display: none; }
<div class="row experiences">
  <main class="experience col-md-12">
    <span class="button is-danger is-small text-right is-rounded" data-toggle="modal" data-target="#ExperienceDeleteModal{{ $experience->id }}"><i class="far fa-trash-alt"></i></span>
    <span class="button is-link is-small text-right is-rounded" data-toggle="modal" data-target="#ExperienceEditModal{{ $experience->id }}"><i class="fas fa-pen"></i></span>
    <h1>{{$experience->subject}}</h1>
    <p class="subtitle is-6">{{$experience->experience_desc}}</p>
    <hr>
  </main>
  <main class="experience col-md-12">
    <span class="button is-danger is-small text-right is-rounded" data-toggle="modal" data-target="#ExperienceDeleteModal{{ $experience->id }}"><i class="far fa-trash-alt"></i></span>
    <span class="button is-link is-small text-right is-rounded" data-toggle="modal" data-target="#ExperienceEditModal{{ $experience->id }}"><i class="fas fa-pen"></i></span>
    <h1>{{$experience->subject}}</h1>
    <p class="subtitle is-6">{{$experience->experience_desc}}</p>
    <hr>
  </main>
  <main class="experience col-md-12">
    <span class="button is-danger is-small text-right is-rounded" data-toggle="modal" data-target="#ExperienceDeleteModal{{ $experience->id }}"><i class="far fa-trash-alt"></i></span>
    <span class="button is-link is-small text-right is-rounded" data-toggle="modal" data-target="#ExperienceEditModal{{ $experience->id }}"><i class="fas fa-pen"></i></span>
    <h1>{{$experience->subject}}</h1>
    <p class="subtitle is-6">{{$experience->experience_desc}}</p>
    <hr>
  </main>
</div>

If your

@include('frontend.profile.experience.edit')
or
@include('frontend.profile.experience.delete')
insert a main element, this solution may need further tweaking...

Answer №2

When you are returning <main /> for each iteration, it is important to assign a unique id to each one.

<main class="experience" id="experience-{{$experience->id}}">
 <h1>{{$experience->subject}}</h1>
 <p class="subtitle is-6">{{$experience->experience_desc}}</p>
 <hr>
</main>

In your CSS, ensure that your rule is adjusted to:

.experience:last-child hr {
   display:none;
} 

Answer №3

For those working with Laravel, take advantage of the $loop variable:

@if (!$loop->last)
    <hr />
@endif

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Django views functions do not receive any data during execution

Things are running smoothly, but it appears that the post function in views.py is not receiving any data. Also, how can I create a submit button using pure JavaScript without reloading the page? views.py: from django.shortcuts import render from rest_frame ...

Processing information on the second page following the activation of a button on the first page using the Console Browser

Is there a way to ensure that the 2nd page has completely loaded before manipulating data on it using JavaScript or jQuery? The commands are currently being executed in the browser console. Attempting to use a setTimeout function to wait for the 2nd page ...

Can you explain the purpose of CLOUDINARY_DEFAULT_URL and CLOUDINARY_DEFAULT_PUBLICID to me?

Need help with my user sign up page Here is my .env file This is my signup controller code: const User = require('../model/User'); const bcrypt = require('bcrypt'); const { uploadToCloudinary } = require('../utils/cloudinary&apos ...

Is it possible to incorporate a similar box on a webpage?

I am trying to find a way to add a similar box to a webpage like the one shown in this image. The design I am referring to is from Reddit's theme, but I would like to know how to create a box with a different color and then have another box next to i ...

What is the best approach to designing a dynamic class toggler for a React sidebar?

I am trying to add a specific class to a clicked link within a sidebar. While this works for one link, when I attach the handler to another link and click it, both links get assigned with the new class. Is there a way to make this functionality more like ...

What is the best way to include an icon in a Vue child component?

Struggling to implement the image in the template using both the img tag and as a background. Despite having the correct path to the icon, neither method seems to work. Check out the code snippet here <div> <a href="#" class="icon" > ...

Adjust Element Width Based on Scroll Position

I'm attempting to achieve a similar effect as seen here: (if it doesn't work in Chrome, try using IE). This is the progress I've made so far: http://jsfiddle.net/yuvalsab/op9sg2L2/ HTML <div class="transition_wrapper"> <div ...

Displaying a message in a modal popup once an existing modal popup has been closed - Angular

Hello, I am new to using Angular and I have a question. How can I show a success message in another popup after sending an email from a modal popup? Here is a snippet of my code: <div id="modalViewImportCode" class="modal fade btm-border" role="dialog" ...

What could be causing JQuery to not hide my div when using Bootstrap classes, but instead working with a Bootstrap row?

I've encountered an issue with hiding two div elements in my HTML using jQuery. One is working perfectly fine, but the other one seems to be causing problems. The first div that works has a single class attribute class='row', while the probl ...

Execute HTML code when a button is clicked

I have a piece of HTML code containing all the necessary information about an item for sale on a website, such as title, price, dimensions, and weight. Additionally, it includes an "Add To Cart" button. I have decided to move away from Wix and hand-code m ...

Problem with overflow scroll in Internet Explorer 11

I'm working with two ID selectors, 'top' and 'bottom'. The 'top' div has a "position: relative" setting while the 'bottom' div has a fixed position and overlaps the 'top' div. I have also set an "overf ...

I am attempting to showcase a retrieved value in HTML through an AJAX request, with the help of Flask

Hello everyone, I'm fairly new to web development and currently working on a flask application. My goal right now is to test an AJAX function to ensure it's functioning correctly. This function reads radio inputs from HTML, and my aim is to displ ...

I'm curious about the process behind this. Can I copy a Figma component from a website and transfer it into my

Check out this site for an example: Interested in how uikit.co/explore functions? By hovering over any file, a copy button will appear allowing you to easily paste it into your Figma artboard. Want to know how this works and how to implement it on your o ...

Implementing a Masonry layout within an ASP UpdatePanel

I have an ASP-WebPage where I'm using an UpdatePanel with a Dropdown and Output-Div for dynamically generated Cards. These cards are layouted by Masonry. The content of the Output-Div is bound to the Dropdown selection. Initially, the Masonry-Layout ...

Retrieve an image located outside of a container

I have multiple SVGs inside separate div elements. <div id="divA"> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <rect x="10" y="10" height="130" width="500" style="fill: #000000"/> ...

Using CSS3 to Create a Pie Chart

Looking to design a symmetrical pie chart featuring 6 pieces, each at 60 degrees, using only html and CSS3. Came across an article , but the concept is unclear to me. Seeking assistance or explanation on the classes mentioned in the link: .pieSliceBlue, ...

Employing VAutocomplete component from vuetify in combination with a render function (scoped slot)

Trying to implement the Autocomplete component within a render function but encountering issues with the scopedSlots feature. Here is my code snippet: import { VAutocomplete } from 'vuetify/lib' export default { render (h) { return ...

"Which is better for maximizing the efficiency of an image grid: CSS or Jquery? What are the key

As a UX Designer looking to enhance my coding skills, I must admit my code may not be perfect. Please bear with me as I navigate through this process. I am in the process of revamping my portfolio website. The original seamless grid was created using a Ma ...

I noticed that the Div element automatically resizes whenever I click anywhere on the page using Chrome

Encountering a problem in Chrome V18 where my gray login box resizes automatically whenever I click anywhere on the page. Any insights on what might be causing this behavior? EDIT: I've observed the error message below: event.layerX and event.laye ...

unusual problems with absolute positioning in CSS

I've run into a problem with absolute positioning in my CSS. Oddly, IE 10+ displays correctly, but Chrome gets distorted. See the images below: Any advice would be appreciated. (This distortion seems to have started after the Chrome 52 update) IE ...