gpt4 book ai didi

html - 如何使用:hover on two of the same elements

转载 作者:行者123 更新时间:2023-12-04 15:00:23 25 4
gpt4 key购买 nike

我正在试验 CSS 动画,我制作了一个导航栏,其中的标签具有轮廓,并且波浪效果是通过使用剪辑路径多边形为另一个标签制作动画来制作的。我目前正试图做到这一点,在悬停时,内部元素的高度增加以完全填充轮廓。但我不知道如何将 :hover 与同一标签的两个元素一起使用。我试过 .nthChild 但它似乎没有用。不过,这可能是我的过渡。另外,全屏运行代码段,因为我没有让它响应。谢谢:)

* {
margin: 0;
padding: 0;
pointer-events: all;
}

nav {
align-items: center;
background-color: black;
display: flex;
justify-content: space-around;
min-height: 8vh;
}

.logo{
position: relative;
}

.logo h2 {
font-family: 'Poppins', sans-serif;
color: #fff;
font-size: 32px;
letter-spacing: 5px;
position: absolute;
text-transform: uppercase;
transform: translate(-50%, -50%);
}
.logo h2:nth-child(1)
{
color: transparent;
-webkit-text-stroke: 1px #03a9f4;
}
.logo h2:nth-child(2)
{
animation: animate 3s ease-in-out infinite;
color: #03a9f4;
}

@keyframes animate
{
0%,100%
{
clip-path: polygon(0% 45%, 15% 44%, 32% 50%, 54% 60%, 70% 61%, 84% 59%, 100% 52%, 100% 100%, 0% 100%);
}
50%
{
clip-path: polygon(0% 60%, 16% 65%, 34% 66%, 51% 62%, 67% 50%, 84% 45%, 100% 46%, 100% 100%, 0% 100%);
}
}

.nav-links{
display: flex;
justify-content: space-around;
position: relative;
width: 50%
}

.nav-links li{
list-style: none;
}

.nav-links a {
color: rgb(238, 238, 238);
font-family: 'Poppins', sans-serif;
font-size: 30px;
font-weight: bold;
letter-spacing: 3px;
position: absolute;
text-decoration: none;
text-transform: uppercase;
transform: translate(-50%,-50%);
transition: height 4s;
}

.nav-links a:nth-child(1) {
color: transparent;
-webkit-background-clip: text;
-webkit-text-stroke: 1px #03a9f4;
overflow: hidden;
}

.nav-links a:nth-child(2) {
animation: animate 3s ease-in-out infinite;
color: #03a9f4;
overflow: hidden;

}

@keyframes animate
{
0%,100%
{
clip-path: polygon(0% 45%, 15% 44%, 32% 50%, 54% 60%, 70% 61%, 84% 59%, 100% 52%, 100% 100%, 0% 100%);
}
50%
{
clip-path: polygon(0% 60%, 16% 65%, 34% 66%, 51% 62%, 67% 50%, 84% 45%, 100% 46%, 100% 100%, 0% 100%);
}
}
<!DOCTYPE html>
<html lang="en">

<head>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Liquid</title>
</head>

<body>

<nav class="nav">
<div class="logo">
<h2>Nav</h2>
<h2>Nav</h2>
</div>
<ul class="nav-links">
<li>
<a id='outline' href="./index.html"><h3>Home</h3></a>
<a id='wave' href="./index.html"><h3>Home</h3></a>
</li>

<li>
<a id='outline' href="./contact.html"><h3>Contact</h3></a>
<a id='wave'href="./contact.html"><h3>Contact</h3></a>
</li>

<li>
<a id='outline' href="./canvas.html"><h3>Visualizer</h3></a>
<a id='wave'href="./canvas.html"><h3>Visualizer</h3></a>
</li>
</ul>
</nav>

<script src="app.js" charset="utf-8"></script>

</body>

<main></main>

</html>

最佳答案

在这种情况下,您将需要两个选择器:

  • .nav-links a:nth-child(1):hover + a
  • .nav-links a:nth-child(2):hover

你可以用逗号将它们组合起来,像这样:

.nav-links a:nth-child(1):hover + a,
.nav-links a:nth-child(2):hover {
animation: none;
}

工作示例:

* {
margin: 0;
padding: 0;
pointer-events: all;
}

nav {
align-items: center;
background-color: black;
display: flex;
justify-content: space-around;
min-height: 8vh;
}

.logo{
position: relative;
}

.logo h2 {
font-family: 'Poppins', sans-serif;
color: #fff;
font-size: 32px;
letter-spacing: 5px;
position: absolute;
text-transform: uppercase;
transform: translate(-50%, -50%);
}
.logo h2:nth-child(1)
{
color: transparent;
-webkit-text-stroke: 1px #03a9f4;
}
.logo h2:nth-child(2)
{
animation: animate 3s ease-in-out infinite;
color: #03a9f4;
}

.nav-links{
display: flex;
justify-content: space-around;
position: relative;
width: 50%
}

.nav-links li{
list-style: none;
}

.nav-links a {
color: rgb(238, 238, 238);
font-family: 'Poppins', sans-serif;
font-size: 30px;
font-weight: bold;
letter-spacing: 3px;
position: absolute;
text-decoration: none;
text-transform: uppercase;
transform: translate(-50%,-50%);
transition: height 4s;
}

.nav-links a:nth-child(1) {
color: transparent;
-webkit-background-clip: text;
-webkit-text-stroke: 1px #03a9f4;
overflow: hidden;
}

.nav-links a:nth-child(2) {
animation: animate 3s ease-in-out infinite;
color: #03a9f4;
overflow: hidden;

}

@keyframes animate
{
0%,100%
{
clip-path: polygon(0% 45%, 15% 44%, 32% 50%, 54% 60%, 70% 61%, 84% 59%, 100% 52%, 100% 100%, 0% 100%);
}
50%
{
clip-path: polygon(0% 60%, 16% 65%, 34% 66%, 51% 62%, 67% 50%, 84% 45%, 100% 46%, 100% 100%, 0% 100%);
}
}

.nav-links a:nth-child(1):hover + a,
.nav-links a:nth-child(2):hover {
animation: none;
}
<!DOCTYPE html>
<html lang="en">

<head>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Liquid</title>
</head>

<body>

<nav class="nav">
<div class="logo">
<h2>Nav</h2>
<h2>Nav</h2>
</div>
<ul class="nav-links">
<li>
<a id='outline' href="./index.html"><h3>Home</h3></a>
<a id='wave' href="./index.html"><h3>Home</h3></a>
</li>

<li>
<a id='outline' href="./contact.html"><h3>Contact</h3></a>
<a id='wave'href="./contact.html"><h3>Contact</h3></a>
</li>

<li>
<a id='outline' href="./canvas.html"><h3>Visualizer</h3></a>
<a id='wave'href="./canvas.html"><h3>Visualizer</h3></a>
</li>
</ul>
</nav>

<script src="app.js" charset="utf-8"></script>

</body>

<main></main>

</html>

关于html - 如何使用:hover on two of the same elements,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67042394/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com