我创建了菜单栏和菜单图标
我想要做的是当悬停在菜单图标上时,菜单栏应该从左侧切换但是它不起作用所以请帮我做...
的链接以下是我的代码
body {
background-color: #F2D7EE;
margin: 0;
padding: 0;
}
.menuico {
background-color: black;
cursor: pointer;
width: 20px;
height: 4px;
margin: 2px;
position: relative;
left: 170px;
z-index: 1;
}
.navmenu {
position: fixed;
background-color: #0E103D;
height: 100%;
//width: 0px;
width: 150px;
color: #F2D7EE;
font-size: 25px;
}
.nav {
margin: 5px;
margin-top: 10px;
}
.mainMenu {
margin-top: 70px;
}
.mainMenu:hover {
cursor: pointer;
}
.menuico:hover .navmenu {
width: 150px;
display: block;
transition: 1s;
}
<div class="navmenu">
<div class="menuico"></div>
<div class="menuico"></div>
<div class="menuico"></div>
<div class="nav">
<div class="mainMenu">AboutMe</div>
<div class="mainMenu">contact-us</div>
<div class="mainMenu">Project</div>
<div class="mainMenu">Blog</div>
<div class="mainMenu">More</div>
</div>
</div>
答案 0 :(得分:2)
你无法控制其他元素悬停的元素,只能控制元素内部或之后的元素。
.menu {
width:20%;
left:-20%;
height:100%;
position:fixed;
background-color:red;
transition: left 0.5s ease-in-out;
}
.icon:hover + .menu {
left:0%
}
&#13;
<div class="icon">icon</div>
<div class="menu"></div>
&#13;