gpt4 book ai didi

javascript - 如何让这个箭头不断旋转

转载 作者:行者123 更新时间:2023-11-28 19:17:50 26 4
gpt4 key购买 nike

所以我决定构建一个导航栏,但其中有一个下拉菜单,所以我这样做了,但我不知道如何让箭头不断旋转,直到下拉菜单消失。请帮忙。

我尝试过 javascript 和其他 CSS 技巧,但没有想到。如果我最终需要为此使用 javascript,那很好,我只希望它能工作:)

我希望箭头一直旋转直到下拉内容消失。

* {
margin: 0;
padding: 0;
font-family: Arial, Helvetica, sans-serif;
outline: 0;
}


/* ===== HEADER ===== */

header {
padding: 20px 30px 40px 0;
box-shadow: 0 1px 10px rgba(0, 0, 0, .11);
}

header nav {
float: right;
}

header li {
margin: 0 .5em;
display: inline-block;
}

header a {
font-size: 20px;
text-transform: capitalize;
text-decoration: none;
color: #666666;
transition: .2s;
}

header a:hover {
color: black;
}

header .dropdown-link {
padding-right: 5px;
}

header i {
cursor: pointer;
transition: .35s;
}

header .dropdown-link:hover+i,
header i:hover {
transform: rotate(180deg);
}

header i:hover+.dropdown-content {
display: grid;
}

.dropdown-link {
padding: 20px 0;
}


/* ===== DROPDOWN-CONTENT ===== */

.dropdown-content {
display: none;
position: absolute;
margin: 10px 0 0 0;
padding: 10px 20px;
background-color: white;
/* 0 x and y offset, 10px blur and 5px size */
box-shadow: 0 0 10px 5px rgba(0, 0, 0, .11);
border-radius: 10px;
}

.dropdown-content:hover {
display: grid;
}

.dropdown-link:hover~.dropdown-content {
display: grid;
}

.dropdown-content a {
padding: 5px 0;
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />


<header>
<nav>
<ul>
<li><a href="#">home</a></li>
<li><a href="#">features</a></li>
<li class="dropdown-item">
<a class="dropdown-link" href="#">dropdown</a>
<i class="fa fa-chevron-down"></i>
<div class="dropdown-content">
<a href="#">link 1</a>
<a href="#">link 2</a>
<a href="#">link 3</a>
<a href="#">link 4</a>
<a href="#">link 5</a>
</div>
</li>
<li><a href="#">contact</a></li>
<li><a href="#">about</a></li>
</ul>
</nav>
</header>

最佳答案

问题是当您将鼠标悬停在 <a> 上时,您需要更改图标标签(dropdown-link)。您需要将鼠标悬停在 li 上( dropdown-item ) 元素,所以当显示 UL 时,从技术上讲,您仍然悬停在 li 上.

这是重要的代码(也是唯一更新的代码):

header .dropdown-item:hover > i,
header i:hover {
transform: rotate(180deg);
}

* {
margin: 0;
padding: 0;
font-family: Arial, Helvetica, sans-serif;
outline: 0;
}


/* ===== HEADER ===== */

header {
padding: 20px 30px 40px 0;
box-shadow: 0 1px 10px rgba(0, 0, 0, .11);
}

header nav {
float: right;
}

header li {
margin: 0 .5em;
display: inline-block;
}

header a {
font-size: 20px;
text-transform: capitalize;
text-decoration: none;
color: #666666;
transition: .2s;
}

header a:hover {
color: black;
}

header .dropdown-link {
padding-right: 5px;
}

header i {
cursor: pointer;
transition: .35s;
}

header .dropdown-item:hover>i,
header i:hover {
transform: rotate(180deg);
}

header i:hover+.dropdown-content {
display: grid;
}

.dropdown-link {
padding: 20px 0;
}


/* ===== DROPDOWN-CONTENT ===== */

.dropdown-content {
display: none;
position: absolute;
margin: 10px 0 0 0;
padding: 10px 20px;
background-color: white;
/* 0 x and y offset, 10px blur and 5px size */
box-shadow: 0 0 10px 5px rgba(0, 0, 0, .11);
border-radius: 10px;
}

.dropdown-content:hover {
display: grid;
}

.dropdown-link:hover~.dropdown-content {
display: grid;
}

.dropdown-content a {
padding: 5px 0;
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />


<header>
<nav>
<ul>
<li><a href="#">home</a></li>
<li><a href="#">features</a></li>
<li class="dropdown-item">
<a class="dropdown-link" href="#">dropdown</a>
<i class="fa fa-chevron-down"></i>
<div class="dropdown-content">
<a href="#">link 1</a>
<a href="#">link 2</a>
<a href="#">link 3</a>
<a href="#">link 4</a>
<a href="#">link 5</a>
</div>
</li>
<li><a href="#">contact</a></li>
<li><a href="#">about</a></li>
</ul>
</nav>
</header>

关于javascript - 如何让这个箭头不断旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57927416/

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