What is the best way to remove the right border in a label for the final child element?

The label in one of my divs returns multiple different names, here is the HTML view:

<div class="customerDisplayFlex">
      <div class="" *ngFor="let cust of customers">
     <label class="dataLabel">
          <input type="radio"
                  name="user-radio"
                  [value]="customer"
                  [ngModel]="currentCustomerContext"
                  (click)="onCustomerContextchange(customer)"
                  class="dataLabel__input" />

          <span class="customer__label">{{customer.firstName | titleCase}} {{ customer.lastName | titleCase}}</span>
        </label>
</div>
</div>

Here is the CSS for the view:

.dataLabel{
color: green;
border-right: 2px solid grey;
}
.dataLabel:last-child{
border-right: none;
}

I even attempted to use Sass:

.dataLabel{
    color: green;
    border-right: 2px solid grey;
&:last-child{
border-right: none;
}
}

For some reason, this setup is not working. Can someone please help me figure out what I am doing wrong? Thank you.

Answer №1

Instead of using :last-child, you should consider using :last-of-type:

.dataLabel {
  color: green;
  border-right: 2px solid grey;
}

.dataLabel:last-of-type {
  border-right: none;
}
<div class="customerDisplayFlex">
  <div class="" *ngFor="let cust of customers">
    <label class="dataLabel">Label 1</label>
    <label class="dataLabel">Label 2</label>
    <label class="dataLabel">Label 3</label>
  </div>
</div>

⋅ ⋅ ⋅

You can also further improve the code by utilizing the :not selector, as shown below:

.dataLabel {
  color: green;
}

.dataLabel:not(:last-of-type) {
  border-right: 2px solid grey;
}
<div class="customerDisplayFlex">
  <div class="" *ngFor="let cust of customers">
    <label class="dataLabel">Label 1</label>
    <label class="dataLabel">Label 2</label>
    <label class="dataLabel">Label 3</label>
  </div>
</div>

I hope this explanation proves to be beneficial.

Answer №2

give this a shot

.dataLabel span:last-child{
border-right: none;
}

Answer №3

Is the last element truly the final child within its container? (not just the concluding label?). (Typically, an input tag or something similar would follow)

If you are referring to the last label tag, consider using :last-of-type instead of :last-child


AFTER receiving feedback and additional code being incorporated into the question:

If all instances of .customerDisplayFlex are within another container that has no further content following them, this approach should be effective:

.customerDisplayFlex:last-child label { border-right: none; }

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 method for selecting the element currently under the mouse cursor?

Is it possible to change the color of all elements you hover over using plain Javascript without jQuery? HTML <ul> <li></li> <li></li> <li></li> </ul> JavaScript (function() { var item = ...

BorderWoocommerce

Something odd has appeared around my shopping cart total ("WARENKORB SUMME") today. Could you please take a look at the screenshot below? Any idea how to remove it? This is for a Wordpress/WooCommerce store. I haven't made any recent changes - I su ...

What is the best way to extract this content from the HTML using Selenium Webdriver?

My goal is to extract the text "1532.6788418669355" from this HTML code, but I've been facing challenges in doing so. Here's what I've attempted: IList options = Driver.FindElements(By.XPath(".//span//*")); Options[0].Text = "" There are n ...

Retrieve the checkbox-success value for each row in the mvc table

I am facing an issue with retrieving the id of each table row when using the bootstrap checkbox-success. However, the normal checkbox allows me to successfully obtain the correct Id for each row. Can anyone assist me in troubleshooting my JavaScript code? ...

Looking to spice up your jQuery modal dialog with unique and varied styles?

Can anyone explain why the grid displayed in our jQuery modal dialog (jqGrid) appears with different styles, specifically font size, compared to the grid on our main screen? I would appreciate any insights or suggestions. ...

What is the best way to add a directional hover effect to a filter?

I am attempting to implement a sliding hover filter effect on an image. The original filter I have is set to grayscale(1). What I want to achieve is for the filter to transition directionally instead of having a slider overlay effect, in order to change i ...

The value of the ng-model checkbox does not update or change when the checkbox is clicked

There is a checkbox being used in the code snippet below: <input type="checkbox" ng-click="toggleShowOtherUserConfiguration()" ng-model="showOtherUserConfiguration" name="ShowOtherUserConfiguration" value="showOtherUserConfigurati ...

How to make a specific table row stand out using AngularJS and CSS

Can you provide advice on how to highlight a specific row in a table? I have a table along with some angular code snippets. Here's an example: angular.module('myApp', []).controller('myTest', function($scope) { var data = []; ...

Make sure to always display the status bar and soft keys

Is there a way to set up my ionic app on Android so that the status bar is always displayed at the top and the soft keys are shown at the bottom? I attempted to add this line to the config.xml file, but it didn't work. <preference name="Fullscree ...

Creating a real-time search feature with dual streams of terms in Angular 2

After diving into the Angular 2 documentation, I was able to grasp how to implement a live search feature using just one term as a parameter. private searchTermStream = new Subject<string>(); search(term: string) { this.searchTermStream.next(term); ...

How can we create a stylish HTML table using CSS display:table and SASS in a sophisticated manner?

Is there a more stylish approach to styling this HTML table using CSS display: table with Sass? Instead of using traditional table elements, I have created a table layout using display: table CSS styles applied to div elements: <div style="display: ...

Exploring the additional capabilities of Full Featured textAngular

I've recently obtained textAngular from the following source: https://github.com/mfrye/textAngular My main interest lies in accessing the additional features such as color-picker and font-size/family. Below are the script links I have included: < ...

The Bootstrap 4 navigation bar remains expanded on tablet screens

I recently obtained and modified a basic bootstrap 4 theme. By customization, I mean that I ensured all menu items have the same margin and added my logo. The issue I encountered is that on tablets, the navbar does not collapse as expected. I have attache ...

Display the homepage if a user accesses a page intended for an ajax request

Currently, I am utilizing jQuery to create a straightforward website. The main page is called 'index.html' and it has the capability to load different content (such as 'info1.html' or 'info2.html') through jQuery ajax requests ...

Think about using floated elements to determine the width of blocks

Consider this example HTML markup (link to jsFiddle): <div style="float: right; width: 200px; height: 200px; background-color: red; margin: 0 20px 0 30px;"> Block 1 </div> <div style="height: 100px; background-color: green;">Block ...

Toggle the visibility of divs using jQuery for easy filtering

I am looking to enhance my filtering system by allowing users to apply and view multiple filters simultaneously. For example, I want to be able to select 'High' and 'pizza' filters and see the results that match both criteria. Currently ...

What is the best way to upload an object in React using fetch and form-data?

Currently, I am facing an issue where I need to send a file to my express app as the backend. The problem lies in the fact that my body is being sent as type application/json, but I actually want to send it as form-data so that I can later upload this file ...

Adjust the cell text overflow based on the width of the table

I am working with a table that has multiple columns. I want the first 3 columns to have a larger width than the others, specifically taking up 15% each for a total of 45% of the table's width. Currently, I am using this code in a sandbox environment: ...

Is it possible to trick the desktop browser into utilizing mobile-designed media queries?

While I've come across numerous solutions on Stack Overflow for displaying a desktop version on mobile devices, my inquiry is centered around the idea of forcing a browser to show a mobile version of a website on a desktop computer. Is there a way to ...

Getting the next sibling element with Selenium: A complete guide

Having trouble targeting a textbox after the label "First Name" in a list to enter a first name. Here's what I've tried: WebElement firstNameLocTry = driver.findElement(By.xpath("//label[text()='First Name']/following-sibling::d ...