The final element in the list will consistently be replaced with a specific item upon completion

In my creative list-making process, I have devised a method using CSS to visually enhance the elements. For the first and middle li items in the list, I add a +, while for the final element, I replace it with an =.

I envisioned this structure: 1 + 2 + 3 = Result However, what I ended up with was: 1 + 2 + 3 + Result

Take a look at my code snippet below:

.list-look{
    padding-left: 0;
    overflow: hidden;
}
ul li{
    list-style: none;
}
.list-look li.itemsLook{
    padding-right: 10px;
    display: inline-block;
    float: left;
    width: 270px;
    position: relative;
  list-style: none;
}
ul li.itemsLook:not(:last-child)::before{
    speak: none;
    font-style: normal;
    font-weight: 900;
    font-variant: normal;
    text-transform: none;
    content: "+";
    
    float: right;
    font-size: 35px;
    width: 10px;
    top: 25%;
    right: 15px;
  
}
ul li.itemsLook:last-child::before{
    content: "=";
   
    float: right;
    top: 25%;
    
}
<ul class="list-look">
  <li class="itemsLook">1</li>
  <li class="itemsLook">2</li>
  <li class="itemsLook">3</li>
  <div>
    Result
  </div>
</ul>

Answer №1

:last-child targets any element. To specifically target the last <li> element, use :last-of-type in your code:

.list-look{
    padding-left: 0;
    overflow: hidden;
}
ul li{
    list-style: none;
}
.list-look li.itemsLook{
    padding-right: 10px;
    display: inline-block;
    float: left;
    width: 4em;
    position: relative;
    list-style: none;
}
ul li.itemsLook:not(:last-of-type)::before{
    speak: none;
    font-style: normal;
    font-weight: 900;
    font-variant: normal;
    text-transform: none;
    content: "+";
    
    float: right;
    font-size: 35px;
    width: 10px;
    top: 25%;
    right: 15px;
  
}
ul li.itemsLook:last-of-type::before{
    content: "=";
   
    float: right;
    top: 25%;
    
}
<ul class="list-look">
  <li class="itemsLook">1</li>
  <li class="itemsLook">2</li>
  <li class="itemsLook">3</li>
  <div>
    Result
  </div>
</ul>

Answer №2

Your example isn't functioning as anticipated because there seems to be a misunderstanding about how :last-child operates. It is not intended to modify the last li.itemsLook element, but rather applies only if that element is the final child of the ul (which it isn't in this scenario due to a div being present as the final child. https://www.w3schools.com/cssref/sel_last-child.asp

To work around this issue, consider moving the div out of the ul as shown below:

<ul class="list-look">
  <li class="itemsLook">1</li>
  <li class="itemsLook">2</li>
  <li class="itemsLook">3</li>
</ul>
<div>
  Result
</div>

Once done, include ul, div { display: inline} in your CSS.

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

What is the best way to create an HTML5 Range that gracefully degrades?

I want to incorporate the <input type='range' /> element from HTML5 for modern browsers and fallback to a <select /> if needed. Since I am working with Ruby-on-Rails, as a last resort, I could implement something similar to this on th ...

Inadequate input when clicking on an external hyperlink

While working on a web page within a React application, I encountered text that originates from an API. To handle embedded links in the text, I decided to utilize linkify-html in order to convert them into clickable anchor tags. Each anchor tag represent ...

What is the reason for Selenium only capturing a portion of the HTML content on a webpage?

I attempted to utilize selenium in order to navigate the web-untis webpage and locate any tests scheduled for this week, but I am facing difficulty in locating the web-elements within the html-file that contain the lesson data. Although other elements such ...

Embedding Google Script (GS) content into an HTML dialog: A step-by-step guide

I am currently working on designing a user interface for my Google sheet. After crafting the necessary .gs function to retrieve the desired value, I proceeded to create an HTML dialog showcasing the required window. While I have successfully filled the di ...

Steps to creating a dynamic transformation of an INPUT field into a TEXTAREA within a Bootstrap4/jQuery web application

I'm curious about a way to have an INPUT field automatically transform into a TEXTAREA in the browser under specific conditions, such as the length of the text within it. Is there a method to achieve this without needing additional logic on the server ...

Using a combination of HTML and JavaScript to verify the accuracy of the password entered

I'm in the process of creating a website where users can input a code and be redirected to a specific page. It's crucial that each unique code leads the user to a different destination. For example, code 123 should take them to index.html while ...

div with a fixed element inside that is scrollable

Check out this jsfiddle: http://jsfiddle.net/devboell/kjFps/ I am trying to create a div that overflows both horizontally and vertically. Additionally, I need an element that scrolls only horizontally while remaining fixed vertically. Here is an explanat ...

Overflow issue with Bootstrap 4 cards on small screens

When working on my application, I find myself using the bootcard .card class quite frequently. However, I've noticed that when switching to mobile view, there is a significant overflow issue that causes a display bug and shifts my entire page out of ...

Find all paragraphs with the CSS property "background-color" using JQuery

My task involves modifying the CSS of a paragraph tag that has a background color of #aaddff. The code I have written seems to be missing something, as the border is not appearing as expected. Should I use element.style or is there a different approach I ...

Padding-left may cause text to not wrap correctly

Every link in the left menu has a padding-left: 15px;. This is done to accommodate a background image (the blue arrow). However, when text wraps (like in "Paintings, prints, and watercolours"), it seems to ignore the padding. I've searched extensive ...

div with fixed position and scrollable content

I'm exploring ways to create a simple webpage layout inspired by the traditional index setup. The idea is to have a fixed header/navbar div that is 200px in height, with a second div below it containing scrollable content that fills the remaining vert ...

A method for setting a value from an HTML textbox to a variable and displaying it on the same page

How can I retrieve the value from a textbox and display it on the same page? The purpose behind this is that when the user enters their BTC wallet into the textbox, I want to store this value in a variable on the same page and then output the value. I at ...

In the Firebug console, Ajax posts are highlighted in a vibrant red color

Upon executing the code provided, the Firebug was enabled. While submitting the form, in the console, the message "post to login_submit.php" appeared in red. However, there was no response received as well. <!DOCTYPE html> <html> ...

Could someone please advise me on how to prevent the second animation from being overridden?

After attempting to separate the animations with a comma and placing them on the same transform, I am still encountering issues. * { margin: 0px; padding: 0px; box-sizing: border-box; } html, body { width: 100%; height: 100%; } .container { ...

Utilizing Jquery for draggable/droppable functionality in combination with custom overflow styles

Encountering a challenge with a drag and drop system that utilizes CSS overflow properties to enable vertical scrolling of a list of values. The issue arises when dragging an item between selected and unselected areas, causing the dragged item to disappear ...

Try utilizing the adjacency selector in Less again

Is it feasible to repeat this pattern an unlimited number of times using Less with the provided CSS selectors? I've been looking into using loops, however, I haven't come across any examples that achieve a similar result. .page-section { ba ...

What is the best way to send a variable from a Django template to views?

index.html {% if request.session.visitor_language == 'en' %} {% with current_page=request.resolver_match.url_name %} {{current_page}} {% endwith %} My name is Khan <a style="color: blue;" href=" ...

Generate a new nested div if there is already a different child present at the specified coordinates (x, y)

My goal is to add a textarea to a sidebar on the right whenever a click is made on the page. The current code I have is as follows: $('#page_to_be_clicked').click(function(e){ var offset = $(this).offset(); var comment_box_y_coord = e.pa ...

When placed in an absolute position, Overflow seems to be malfunctioning

Within a div that is positioned relatively, there is another div positioned absolutely. Despite setting overflow:hidden and border-radius on the main div, the inner div's edges are not contained within the main one, indicating that the overflow proper ...

I am unable to view the data in the autocomplete drop-down menu

I'm currently encountering an issue with my autocomplete feature. Whenever I click on the input field, a dropdown menu should appear with all available options to choose from. However, I am having trouble with the visibility of these fields. I have t ...