【发布时间】:2016-06-09 22:59:20
【问题描述】:
练习锚标签和下拉菜单。在以下代码中,下拉菜单不起作用。不知道为什么。包含文本“这是下拉菜单”的 div 应该恰好出现在包含文本“这是文本。它在中心”的 div 下方,只要后者悬停在上面。两个 div 的宽度相同。
html,body {
margin: 0px;
height: 100%;
/* [disabled]width: 100%; */
left: 0px;
top: 0px;
background-color: rgba(255,255,255,1);
}
.wrapper {
text-align: center;
margin-top: 0;
margin-left: auto;
height: 100%;
max-width: 960px;
background-color: rgba(0,0,0,1);
margin-right: auto;
position: relative;
}
.link1 {
height: auto;
width: 50%;
color: rgba(255,255,255,1);
margin-right: auto;
margin-left: auto;
background-color: rgba(204,204,204,1);
}
.link1 a {
text-decoration: none;
display: block;
}
.link1 a:hover {
text-decoration: underline;
background-color: rgba(255,0,0,1);
}
.link1 a:hover .dropdown {
display: block;
}
.dropdown
{
height: 25%;
width: 50%;
background-color: rgba(204,204,204,1);
margin-right: auto;
margin-left: auto;
text-align: center;
display: none;
}
<div class="wrapper">
<div class="link1">
<a href="http://www.hotmail.com">This is text. Its in center</a>
</div>
<div class="dropdown">This is dropdown menu</div>
</div>
【问题讨论】:
-
那是因为你的 .dropdown 元素不是链接的兄弟。
-
能否请您提供代码示例以便我更好地理解?