Unable to attach a tooltip to a list item

As an Angular developer, I am working on a list element that displays all the cars and I am looking to add a tooltip to enhance its visual appeal.

Here is what I have attempted so far:

I created a span tag with the class "tooltip" to wrap around the ul element. With CSS, I applied the "position: relative" property. Inside the list element, I inserted another span tag containing the text for the tooltip and set its display to none using CSS. Then, I implemented some CSS rules to ensure that the tooltip appears upon hovering over the list element. Refer to the code snippet below for more details.

Please note that the specific list element I want the tooltip to show when hovered over is labeled as "All Brands".

In my brand.component.html file:

<span class="tooltip">
    <ul *ngIf="dataLoaded==true" class="list-group">
        <li (click)="currentBrand=null" routerLink="/cars" class="list-group-item" [ngClass]="{'active': !currentBrand}">
            <span class="text">
                Listed All Cars
            </span> 
            All Brands
        </li>
        <li class="list-group-item" (click)="currentBrand = brand" routerLink="/cars/brand/{{brand.brandId}}" [ngClass]="{'active': currentBrand === brand}" *ngFor="let brand of brands">{{brand.brandName}}</li>
    </ul>
</span>

In the brand.component.css file:

/* Tooltip */

.tooltip {
    position: relative;
}

ul li:first-child .text {
    display: none;
    width: 120px;
    background-color: black;
    color: #fff;
    text-align: center;
    border-radius: 5px 0;
    padding: 5px 1px;
    z-index: 1;
}

ul li:first-child:hover ul li:first-child .text {
    display: inline-block;
    position: absolute;
}

ul li:first-child .text::after {
    content: "";
    position: absolute;
    bottom: 110%;
    right: 90%;
    border: 5px solid;
    border-color: black transparent transparent transparent;
}

Your input and advice are deeply appreciated. Thank you in advance!

Answer №1

Resolved the CSS issue by adjusting the tooltip text to have a visibility: hidden; instead of none

.tooltip {
  position: relative;
  display: inline-block;
  border-bottom: 1px dotted black;
}

.tooltip .tooltiptext {
  visibility: hidden;
    width: 120px;
    background-color: black;
    color: #fff;
    text-align: center;
    border-radius: 5px 0;
    padding: 5px 1px;
    z-index: 1;

  /* Position the tooltip */
  position: absolute;
  z-index: 1;
}

.tooltip:hover .tooltiptext {
  visibility: visible;
}
span: {
    display: none;
    width: 120px;
    background-color: black;
    color: #fff;
    text-align: center;
    border-radius: 5px 0;
    padding: 5px 1px;
    z-index: 1;
}



ul li:first-child:hover ul li:first-child .text {
    display: inline-block;
    position: absolute;
}

ul li:first-child .text::after {
    content: "";
    position: absolute;
    bottom: 110%;
    right: 90%;
    border: 5px solid;
    border-color: black transparent transparent transparent;
}
<!DOCTYPE html>
<html>
<style>

</style>
<span class="tooltip">
        <ul *ngIf="dataLoaded==true" class="list-group">
            <li (click)="currentBrand=null" routerLink="/cars" class="list-group-item" [ngClass]="{'active': !currentBrand}">
                <span class="tooltiptext">
                    Listed All Cars
                </span> 
                All Brands
            </li>
            <li class="list-group-item" (click)="currentBrand = brand" routerLink="/cars/brand/{{brand.brandId}}" [ngClass]="{'active': currentBrand === brand}" *ngFor="let brand of brands">{{brand.brandName}}</li>
        </ul>
    </span>


</body>
</html>

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

Angular package that includes horizontal scrolling functionality with arrow buttons

Currently seeking an Angular 2-6 package featuring a horizontal image scroll with arrows, similar to the functionality on Airbnb: Any suggestions or recommendations are greatly appreciated – thank you! ...

Issues with updating in Firebase real-time database using Angular 2 are not

I am currently working on a simple app that inserts new records into Firebase. Below the input field, the app lists the last 10 items in the database. ISSUE: I am facing a problem where I have to start inputting something in the input field or click on ...

Child routes in Angular tabs are failing to display in the currently active tab

Hey there! I'm currently working on navigating my Angular application using tabs, and I've run into a bit of an issue with the child routes. Specifically, when I switch to the second child route within the second tab, the status of the tab change ...

Enhance Your Joomla 2.5 Website with Custom CSS Specifically for iPad Viewing

Is there a way to load a specific CSS file when accessing my Joomla website through an iPad? I am running Joomla version 2.5. Although I have set up style-sheets for browsers like Internet Explorer and Firefox, I am unsure how to target the website to lo ...

Unable to attach to the property 'displayQR' as it is not recognized by the 'div'?

I'm facing an issue with a div structure that looks like this <div class="empower-btn" [showQR]="showQR" [selectedCoin]="coin" [availableAmount]="getCoinAmount()" [ ...

tips for replacing multiple route parameters in Angular using the replace function

I am facing an issue when trying to replace multiple parameters using the angular replace function. The problem is that the function only detects the first parameter. For example, if I have this route admin/management/{type}/card/{id}, and use the route.r ...

Generate additional tabs

Currently, I am in the process of working on a project where I have a bar that will contain dynamically filled tabs. My goal is to include a (+) image that becomes visible when the bar is full. When a user clicks on this image, the remaining tabs should ap ...

What is the best way to make a bootstrap component (container) stretch to the full width and height of the window when it first loads, and which

I am looking to achieve something similar to the design on a certain website: The goal is to have a container with a background and a form inside that resizes proportionally based on the size of the window it is opened in. The resizing should be smooth an ...

Tips for concealing items on a website within a WebView

Is it possible to hide the header element with the search bar and logo when loading this page on a Webview? I'm not familiar with JavaScript, so is there a way to achieve this? The section I am looking to conceal ...

What are some solutions for adjusting this sidebar for mobile devices?

My mobile version sidebar is not functioning properly on my website. To see the issue, you can visit Zinexium. As I am new to HTML, I don't know how to fix it. Here is a link to the code. Thank you! <!DOCTYPE html> // Code snip ...

Having trouble with my jQuery .hover() code not running as expected

Whenever I hover over my divs, I want them to change color. However, the code doesn't seem to be working as expected when I try to do so. I suspect that the issue might be related to the z-index property used in the class that I am trying to hover ove ...

What is the process of combining JS functions with PHP echo in code?

I am currently working on creating a popout menu for an array of values that are being displayed from the database. The goal is to show the corresponding popout menu when the svg is clicked, but I am running into an issue where it only works for the first ...

unable to display loading image prior to upload

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html lang="en"> <head> <title>Unique Prints</title> <meta charset="utf-8"> <meta name="viewport" conte ...

How to Animate the Deletion of an Angular Component in Motion?

This stackblitz demonstration showcases an animation where clicking on Create success causes the components view to smoothly transition from opacity 0 to opacity 1 over a duration of 5 seconds. If we clear the container using this.container.clear(), the r ...

Issue with reactivity not functioning as expected within VueJS loop without clear explanation

Struggling with implementing reactivity in vue.js within a loop? The loop renders fine, but firing an event updates the content without visibly rendering the data on the page. The latest version of vue.js is being used with bootstrap and jquery. Despite a ...

What steps can I take to resolve the issue of my popup closing automatically upon opening and simultaneously refreshing my webpage?

After creating a popup in my HTML page, when I click on the element that triggers it, the popup appears for a brief moment before automatically closing and causing my page to refresh. Below is the code I am using: HTML Code : <a class="lv-footer" id= ...

What is the best approach to effectively manage right-to-left text-input fields?

I have been working on a project involving a multilingual layout. One concern that has arisen is: What is the proper way to handle text-input in this scenario? To better explain my issue, I created a JSFiddle. If I simply add the attribute dir="rtl", ...

Show a virtual numeric keypad on the HTML input fields when they are set as type text specifically for mobile devices in a unique situation

When accessing the following web page from a mobile device, I currently have number input fields with comma separators added. However, in order to implement the comma separation function, I had to set the input type to text. This resulted in showing an alp ...

How to create a collapse feature that allows only one item to be open at a time in Angular

I developed an angular app with a collapse feature, but I noticed that multiple collapses can be open at once. I am utilizing Ng-Bootstrap collapse for this functionality. Below is the code snippet from the TS file: public isCollapsed = true; And here is ...

Tips for transferring the ID from one element to another using JavaScript

I'm attempting to create a slideshow using icons all within one class. The "active" style class will have an ID and represent the current picture. By clicking either the left or right button, I aim to change the style of the active class. const l ...