[英]Hover over doesn't work when two items are in different divs?
I want to hover over and show the text but text and logo are in the different div but when I hover over, it doesn't show the text.我想 hover 结束并显示文本,但文本和徽标在不同的 div 中,但是当我 hover 结束时,它不显示文本。
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>
)
}
I also tried display: none and display:block but it still doesn't work and it doesn't show text when I hover the logo我也试过 display: none 和 display:block 但它仍然不起作用并且当我 hover 徽标时它不显示文本
.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;
}
here is my sandbox: https://codesandbox.io/s/unruffled-violet-nklue?file=/pages/index.js这是我的沙箱: https://codesandbox.io/s/unruffled-violet-nklue?file=/pages/index.js
You are currently using a parent selector to select the .githubT
class when the .github
class is hovered.当悬停 .github class 时,您当前正在使用父选择器
.github
.githubT
class。 When you select elements with the syntax: .class1.class2
you are selecting all elements with class2 that are descendants of class1.当您使用语法 select 元素时:
.class1.class2
您正在选择所有具有 class2 的元素,这些元素是 class1 的后代。
Try putting the:hover pseudo class on your anchor tag and selecting .githubT
using something like this:尝试将:hover pseudo class 放在锚标记上,然后使用如下方式选择
.githubT
:
a:hover+.githubT {
visibility: visible;
}
(selects an element that comes immediately after the first element). (选择紧跟在第一个元素之后的元素)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.