为什么我在 html ul li 中的链接不起作用?
Why are my links in html ul li not working?
我目前正在尝试建立我的第一个网站(作业)。对于我的下拉菜单,我使用了 Dev Ed 的下拉菜单教程,它工作正常,只是我无法单击下拉位中的链接。
(虽然鼠标光标仍然变成那个手形符号)
我该如何解决这个问题?
nav {
grid-column: 1/5;
background: #2E3045;
justify-content: center;
border-radius: 10px;
}
nav a,
button {
text-decoration: none;
font-size: 1.7vw;
font-family: Bahnschrift, sans-serif;
color: #DFB830;
font-weight: bold;
}
/* horizontal-menu */
.menu {
height: auto;
display: flex;
justify-content: space-around;
align-items: center;
}
/* styling horizontal-menu buttons */
.dropdown button,
.dd-buttons {
background: none;
border: none;
cursor: pointer;
text-transform: uppercase;
padding-top: 1%;
padding-bottom: 1%;
}
.menu button:hover,
.dd-buttons:hover {
color: #ECEEFF;
}
/* styling the dropdown arrow */
@media only screen and (max-width: 480px) {
.menu img {
max-width: 7px;
height: auto;
display: inline-block;
}
}
@media only screen and (min-width: 481px) {
.menu img {
max-width: 15px;
height: auto;
display: inline-block;
}
}
/* dropdown list */
.dropdown {
position: relative;
}
.dropdown ul {
position: absolute;
background: #DFB830;
margin-top: 8px;
min-width: 150%;
display: flex;
justify-content: space-around;
align-items: center;
flex-direction: column;
list-style: none;
border-radius: 5px;
opacity: 0;
pointer-events: none;
transition: all 0.4s ease;
transform: translateY(10px);
}
/* styling dropdown menu list items */
.dropdown li {
width: 100%;
height: 100%;
line-height: 250%;
display: flex;
justify-content: center;
align-items: center;
transition: all 0.4s ease;
}
.dropdown a {
font-size: 1.5vw;
color: #2E3045;
}
/* when hovering over dropdown list */
.dropdown li:hover {
background-color: #E9CF72;
}
.dropdown button:focus+ul {
opacity: 1;
pointer-events: all;
transform: translateY(0px);
}
<!------------------------ menu ------------------------>
<nav>
<div class="menu">
<button class="dd-buttons"><a href="https://www.youthduo.com/" target="_blank">YouthDuo</a></button>
<button class="dd-buttons"><a href="https://www.galacticspirit.com/home.php" target="_blank">Galactic Spirit</a></button>
<div class="dropdown">
<button>Feng Shui <img src="images/dropdown icon.png"></button>
<ul>
<li><a href="#">Feng Shui Basics</a></li>
<li><a href="#">CD's and DVD's</a></li>
<li><a href="#">Books and EBooks</a></li>
</ul>
</div>
<div class="dropdown">
<button>Color Alchemy <img src="images/dropdown icon.png"></button>
<ul>
<li><a href="LIC.html" target="_blank">Living in Color</a></li>
<li><a href="GT.html">Guided Training</a></li>
<li><a href="CAB.html">Jami Lin's Products</a></li>
</ul>
</div>
</div>
</nav>
删除 pointer-events:none
.dropdown ul {
position: absolute;
background: #DFB830;
margin-top: 8px;
min-width: 150%;
display: flex;
justify-content: space-around;
align-items: center;
flex-direction: column;
list-style: none;
border-radius: 5px;
opacity: 0;
transition: all 0.4s ease;
transform: translateY(10px);
}
我目前正在尝试建立我的第一个网站(作业)。对于我的下拉菜单,我使用了 Dev Ed 的下拉菜单教程,它工作正常,只是我无法单击下拉位中的链接。 (虽然鼠标光标仍然变成那个手形符号)
我该如何解决这个问题?
nav {
grid-column: 1/5;
background: #2E3045;
justify-content: center;
border-radius: 10px;
}
nav a,
button {
text-decoration: none;
font-size: 1.7vw;
font-family: Bahnschrift, sans-serif;
color: #DFB830;
font-weight: bold;
}
/* horizontal-menu */
.menu {
height: auto;
display: flex;
justify-content: space-around;
align-items: center;
}
/* styling horizontal-menu buttons */
.dropdown button,
.dd-buttons {
background: none;
border: none;
cursor: pointer;
text-transform: uppercase;
padding-top: 1%;
padding-bottom: 1%;
}
.menu button:hover,
.dd-buttons:hover {
color: #ECEEFF;
}
/* styling the dropdown arrow */
@media only screen and (max-width: 480px) {
.menu img {
max-width: 7px;
height: auto;
display: inline-block;
}
}
@media only screen and (min-width: 481px) {
.menu img {
max-width: 15px;
height: auto;
display: inline-block;
}
}
/* dropdown list */
.dropdown {
position: relative;
}
.dropdown ul {
position: absolute;
background: #DFB830;
margin-top: 8px;
min-width: 150%;
display: flex;
justify-content: space-around;
align-items: center;
flex-direction: column;
list-style: none;
border-radius: 5px;
opacity: 0;
pointer-events: none;
transition: all 0.4s ease;
transform: translateY(10px);
}
/* styling dropdown menu list items */
.dropdown li {
width: 100%;
height: 100%;
line-height: 250%;
display: flex;
justify-content: center;
align-items: center;
transition: all 0.4s ease;
}
.dropdown a {
font-size: 1.5vw;
color: #2E3045;
}
/* when hovering over dropdown list */
.dropdown li:hover {
background-color: #E9CF72;
}
.dropdown button:focus+ul {
opacity: 1;
pointer-events: all;
transform: translateY(0px);
}
<!------------------------ menu ------------------------>
<nav>
<div class="menu">
<button class="dd-buttons"><a href="https://www.youthduo.com/" target="_blank">YouthDuo</a></button>
<button class="dd-buttons"><a href="https://www.galacticspirit.com/home.php" target="_blank">Galactic Spirit</a></button>
<div class="dropdown">
<button>Feng Shui <img src="images/dropdown icon.png"></button>
<ul>
<li><a href="#">Feng Shui Basics</a></li>
<li><a href="#">CD's and DVD's</a></li>
<li><a href="#">Books and EBooks</a></li>
</ul>
</div>
<div class="dropdown">
<button>Color Alchemy <img src="images/dropdown icon.png"></button>
<ul>
<li><a href="LIC.html" target="_blank">Living in Color</a></li>
<li><a href="GT.html">Guided Training</a></li>
<li><a href="CAB.html">Jami Lin's Products</a></li>
</ul>
</div>
</div>
</nav>
删除 pointer-events:none
.dropdown ul {
position: absolute;
background: #DFB830;
margin-top: 8px;
min-width: 150%;
display: flex;
justify-content: space-around;
align-items: center;
flex-direction: column;
list-style: none;
border-radius: 5px;
opacity: 0;
transition: all 0.4s ease;
transform: translateY(10px);
}