difficulty generating a tooltip

Purpose: My main goal is to implement a tooltip feature where hovering over text triggers the display of a tooltip. To achieve this, I am seeking inspiration from an example on w3schools which can be found at this link.

Current Implementation:

render() {
        return (
            <div >
                <h2>Tooltip</h2>
                <p>Hover over the text below:</p>

                <div class = "tooltip">
                    Hover over me 
                    // <img src = "assets/images/react.png" alt="React / React Native" className = "icons"></img>

                    <span class = "tooltiptext">
                        Tooltip text 
                    </span>
                </div>
            </div>
            

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

 .tooltip, .tooltiptext {
  visibility: hidden;
  width: 120px;
  background-color: #555;
  color: black;
  text-align: center;
  border-radius: 6px;
  padding: 5px 0;
  position: relative;
  right: 100px;
  z-index: 1;
  /* bottom: 125%; */
  left: 50%;
  margin-left: -60px;
  opacity: 0;
  transition: opacity 0.3s;
}

.tooltip, .tooltiptext::after {
  content: "";
  position: absolute;
  /* top: 100%; */
  left: 50%;
  margin-left: -5px;
  border-width: 5px;
  border-style: solid;
  border-color: #555 transparent transparent transparent;
}

.tooltip:hover, .tooltiptext {
  visibility: visible;
  opacity: 1;
}

Note: Some positioning styles in the CSS have been temporarily disabled for ease of troubleshooting. Additionally, my end goal is to have the tooltip displayed when hovering over a tech icon, but I am starting with a simple setup.

Current Issue: The "Hover Over Me" text and tooltip are not displaying correctly; they appear white and cannot be seen. However, hovering over the tooltip text reveals both elements. I am working on adjusting the element positions using developer tools. Furthermore, the tooltip itself is not rendering as expected.

https://i.sstatic.net/WlGpA.png

Answer №1

It seems like you may have confused the CSS selectors you are using. The correct selector should be .tooltip .tooltiptext instead of .tooltip, .tooltiptext (without the comma). This way, you can target elements with the class .tooltiptext that are descendants of elements with the class .tooltip, rather than selecting elements that have either class.

Here is some documentation for further clarification.

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

Limit the character count in a textarea

My goal is to control the number of characters that can be entered into a textarea. While I am aware that I could simply use a substring to limit the characters, I prefer to visually inform the user when their text has reached the maximum length. The maxl ...

How can I make a clickable button or link within an anchor tag that is still able to be right-clicked?

Hey there, I'm currently working on a notification dropdown menu where each <li> contains a link or an <a> tag. I'm aiming to create something similar to Facebook's notification system. However, the challenge lies in trying to ...

The Gatsby and React navigator

Hey there, I've run into a little snag while working on my React component. I'm trying to display a pop-up using JS, but when I try to build my Gatsby site, I encounter an error stating: WebpackError: ReferenceError: navigator is not defined. Bel ...

Ways to Fix the React Hydration Issue in Next.js

I have been encountering an issue with the error message "Hydration failed because the initial UI does not match what was rendered on the server." I am unsure of what is causing this error and would appreciate any insights or suggestions from others who ma ...

Creating a Contact Form with Email Submission using Html and Php

Establishing Database Connection $server = 'localhost:8080'; $username = 'root'; $password = ''; $database = 'resort'; $connect = mysqli_connect($server, $username, $password ) or die(mysqli_error.&apos ...

The step-by-step guide to setting up Material-UI Autocomplete with secondaryText for dynamic data transformation

I'm currently facing an issue and it seems like there is a lack of documentation available for this specific problem. The situation is that I am building a website where I have implemented an AutoComplete component to search for data in the database. ...

Tips for dynamically setting up an inputStream in a Java <audio> tag within an HTML5 environment

I need to incorporate a dynamic inputStream from a web service into an HTML5 audio tag so that users can play it. How can I programmatically set the content of the HTML5 tag to achieve this? ...

What is the best method to substitute a comma and period with just a period in a textarea

Creating a text area with auto-replacing characters like straight quotes, double dashes to em dash, and double spaces to single space was simple. However, I'm facing difficulty in adding a script for replacing certain characters: word . as word. wor ...

The Google map is not showing up on the screen despite having entered the API Key

Trying to showcase a Google map on my website. Check out the code below:- <script> function initializeMap() { var coords = {lat: -25.363, lng: 131.044}; var mapObj = new google.maps.Map(document.getElementById('mapz') ...

What to do when a JWT token expires and how to generate a fresh token?

I am currently dealing with a problem regarding JWT (JSON Web Token) authentication in my application. At times, when I make API requests, I encounter the following error response: { "success": false, "message": "jwt expired" } I am aware that this er ...

Tips for populating an array with boolean values when a checkbox change event occurs:

I am looking to fill the answers array with boolean values. The checkboxes on my form are generated dynamically, but there will only be four of them. When a checkbox is unchecked, its corresponding value in the answers array should be false; when checked, ...

An issue arises when creating mesh instances with Context within a Gatsby application utilizing React Three Fiber

I'm working on my Gatsby app and experimenting with using instances to display a mesh multiple times. I found some helpful code on that I'm currently using: import React, { useRef, useMemo, useContext, createContext } from "react" impo ...

Horizontal Scroll HTML

Currently in the process of building a website for my father, everything is going smoothly. I followed a helpful Stackoverflow tutorial to create a specific webpage that I now want to customize with a hyperlink and make it scroll horizontally: Sliding divs ...

"AngularJS directive mandating the use of the required attribute for internal control

I've encountered a challenge with this specific issue. We are using a directive called deeplink, which contains the following code: restrict: 'E', require: 'ngModel', scope: { smDropdown: '=smDeeplinkDropdown', s ...

Experience the advanced NgPrime p-dropdown template with templating, filtering, and a clear icon that collapses when wrapped within a form element

Check out this link for a demo Whenever I enclose the code below in a </form> element, the drop-down menu collapses. <h5>Advanced with Templating, Filtering and Clear Icon</h5> <p-dropdown [options]="countries" [(ngModel)]=& ...

What is the best way to apply a CSS class to my anchor tag using JavaScript?

I have a good grasp of using JavaScript to insert an anchor element into my webpage. For instance, var userName_a = document.createElement('a'); However, I am interested in adding a style name to that same element as well. I attempted the follo ...

Adding static files to your HTML page with node.js

This is not a question about using express.static() In my application, I have multiple pages that share the same JS and CSS dependencies. Instead of adding <script> or <link> tags to every single page, I'm looking for a way to include the ...

The alignment of text in MUI elements is slightly skewed

While using MUI in React (@mui/material), I've noticed a slight vertical off-centering of text in some components. Take, for example, the Chip: https://i.sstatic.net/thhYb.png It might be hard to spot at first, but you can see that the text isn&apos ...

Alignment of Bootstrap input groups and buttons

I am looking to have the input group aligned on the left side and the "Add New" button aligned on the right side of the row. <div class="row"> <div class="input-group col-sm-6"> <input type="text" class="form-control" placehol ...

CSS: The addition selection operator is not functioning as expected

The span's background color is not changing correctly when the radio button is changed. Why is this happening and how can it be fixed? div { margin: 0 0 0.75em 0; } .formgroup input[type="radio"] { display: none; } input[type="radio"], label { ...