Why won't hover over function properly in separate divs for two items?

My goal is to show text when hovering over a logo, but the text and logo are in different divs. Despite trying various solutions like using display: none and display: block, I still can't get it to work.

import styles from '../styles/Float.module.css'
export default function Connection(){
    return(
        <div className={styles.container}>

        <div className={styles.float}>

            <a href="https://github.com/YasamanForouzesh" target="_blank">
                <img className={styles.github} src="/GitHub.png"/>
            </a>
        </div>
        <h1 className={`${styles["h1"]} ${styles["githubT"]}`}>GitHub</h1>
        </div>
    )
}

In my CSS file, I have defined grid layouts for the container and float elements. I also attempted to use the :hover pseudo-class to make the text visible when hovering over the logo, but it didn't work as expected.

.container {
  display: grid;
  grid-template-columns: auto auto;
  grid-template-rows: auto auto auto;
  position: fixed;
  right: 0;
  margin-right: 20px;
  bottom: 0;
  margin-bottom: 40px;
}
.float {
  grid-column: 2;
  grid-row: 1/4;
  display: grid;
  grid-template-columns: auto;
  grid-template-rows: auto auto auto;
  justify-content: center;
  border-radius: 30px;
  background-color: rgb(112, 100, 200);
  opacity: 0.5;
  width: 40px;
}

.github {
  width: 30px;
  height: 30px;
  grid-row: 2;
  margin-top: 20px;
}

.githubT {
  grid-column: 1;
  grid-row: 2;
  visibility: hidden;
}

.github:hover .githubT {
  visibility: visible;
}

You can view my code on CodeSandbox: https://codesandbox.io/s/unruffled-violet-nklue?file=/pages/index.js

Answer №1

At the moment, you are using a parent selector to target the .githubT class when the .github class is hovered over. When you use the syntax: .class1 .class2, you are essentially targeting all elements with class2 that are children of class1.

To improve your code, consider applying the :hover pseudo-class to your anchor tag and selecting the .githubT class with a rule like this:

a:hover+.githubT {
  visibility: visible;
}

(This targets an element that immediately follows the first element).

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

Issue with Angular 6 where data is not binding to the UI on initialization

I am struggling with binding dynamic data to the UI and Data tables on my website. Despite trying various methods, I have not been able to achieve success. Currently, I am using the smart admin latest theme for development. When I make a call to the API, ...

Retrieving a single item from an array of objects with the help of body parser

I need assistance with sending an array of objects to a post route in my express app. Here is my form (written in ejs format): <form action="/archiveList/<%= list._id %>" method="POST"> <input type="hidden" name="list" value = <%= items ...

Storing a JSON as a cookie in a Django response

Is there a way to store a dictionary/json object in a client-side cookie from Django and retrieve it as a JavaScript object? response = HttpResponseRedirect(reverse('app:home')) response.set_cookie('cookiekey', 'value') retu ...

A JavaScript function utilizing lodash's forEach method that is returning an undefined value

I've encountered a problem while developing a ReactJS app. In one of my functions called filterSelected, I have a for loop that iterates through an array of region names (e.g. ["Thailand", "Malaysia"]) and is supposed to return an array of their corre ...

Guidelines for transferring data when a button is held down or pressed

I am looking to continuously send values while a button is pressed. Currently, a value is only sent with each click. Below is the current code: my_custom_script.js $(document).ready(function() { $('#left').mousedown(function() { var left ...

Utilize the appendTo() function and make a switch to dynamically insert content stored in variables into a specified

I am working on developing a page with a central content div, where users have the ability to choose various options that will introduce different additional content. This added content will then present more opportunities for adding new elements, ultimate ...

Adding a stylish underline to text using HTML and CSS

Looking for some assistance with my Html and CSS website project. I am currently facing a challenge trying to place a border below the text as shown in the provided image. Below is the snippet of my Html code: <div class="Sectionheading"> ...

Having trouble getting the custom font to display correctly in xhtml2pdf for a Django project

I'm having trouble incorporating a custom font into my PDF generated from HTML. Although I successfully displayed the font in an HTML file, indicating that the font path is correct and it's being used properly, the .ttf font type doesn't re ...

What is the best way to retrieve a variable from MySQL in a Node.js environment?

var result; function getName(id) { //Retrieve name from database connection.query(`SELECT name FROM users WHERE id = "${id}"`, function (err, rows, fields) { if (err) console.log(err); result = rows[0].name; }); console.lo ...

Using Symfony2 Knp-snappy library for PDF generation, the CSS styling is not being properly imported

Attempting to create a PDF from an html.twig template, but facing some issues... Although the content is correct in the PDF, the layout is missing. It appears that the CSS files are not being imported... Bootstrap from Twitter is being used to handle the ...

Disabling data-scroll-speed on mobile devices

As a beginner in JavaScript/jQuery, I am working on incorporating code that changes the scrolling speed of specific elements on my webpage. However, I am struggling to disable this code for smaller screen widths. Here is the code snippet I have so far: &l ...

Changes will not reflect until a re-deployment is done on Next.js 13 and Sanity

Hey there! Currently, I'm using Next.js version 13 with server components by utilizing the /app directory along with Sanity Studio. Here's a snippet of my code: const Page = async () => { const query = groq`*[_type == "university"] ...

Utilizing JavaScript to assign a CSS class to an <li> list item

I am working on a page that includes a menu feature: https://jsfiddle.net/dva4zo8t/ When a menu button is clicked, the color changes and I need to retain this color even after the page is reloaded: $('[id*="button"]').click(function() { $( ...

Would someone be able to clarify the purpose of this await useState React code?

Recently, I came across some React code that directly modifies the state, which goes against what I was taught. However, when I attempted to update it properly, the functionality broke. Clearly, an issue needs to be fixed, but before diving in, I'd li ...

What are the recommended techniques for utilizing prototypal and prototype-based inheritance in modern JavaScript (ES6) and TypeScript?

Some older discussions on Javascript prototypal inheritance & delegation can be found below: Benefits of prototypal inheritance over classical? classical inheritance vs prototypal inheritance in javascript I am curious about the current (2018) recom ...

Provide the 'URL' of an image in JavaScript

Is it possible to retrieve the image address of an img tag using JavaScript without accessing the src attribute directly? Interestingly, Google Chrome provides a way to copy the image address by right-clicking on an img tag and selecting 'Copy image ...

Move the search bar to the left side of the screen instead of the

Is there a way for the search bar in my navbar's dropup menu to transition from right to left? Currently, the dropup menu is positioned on the far right of the screen as desired, but when I click on the search button, the search bar extends off the sc ...

Input specific ng-if conditions

I'm a bit confused about the conditions for my ng-if and could use some assistance. I have a form on my page that is rendered using ng-repeat and a couple of custom filters. You can check out this plunker. The issue I'm facing is that I need to p ...

Adjusting color schemes for Twitter Bootstrap Tooltips according to their placement

I have been attempting to customize the colors of tooltips (specifically from Twitter Bootstrap), but I am encountering some difficulties. While changing the default color was straightforward, altering the colors for .tooltip and its related definitions ha ...

What is the process of transferring data from one div to another div (table) using AngularJS?

In my quest to enhance my table with JSON data upon clicking the + icon, I am faced with two sections: Pick Stocks where stock names and prices (retrieved from data.json) need to be added to the table found in the Manage Portfolio section. First Section h ...