在一个页面一个以上的滑动菜单

问题描述 投票:0回答:1

我已经成功地使滑动菜单链接,但是当我试图让另一个它不喜欢的第一个工作。

下面是我想要达到一个线框:

Wireframe

/*HOME MENU*/

#home {
  position: fixed;
  left: -8.5em;
  top: 20px;
  width: 8em;
  background: black;
  color: white;
  margin: -1em 0 0 0;
  padding: 0.5em 0.5em 0.5em 2.5em;
  transition: 0.2s
}

#home:hover {
  left: 0
}

#home a {
  position: relative;
  left: 0;
  transition: 0.2s
}

#home a:link {
  color: white;
  text-decoration: none;
}

#home a:visited {
  color: green;
}

#home a:hover {
  color: gray;
}

#home a:active {
  left: -7em;
  background: hsla(80, 90%, 40%, 0.7);
  color: white;
}

#home a:focus {
  left: -7em;
  background: hsla(80, 90%, 40%, 0.7);
}

/*3D MENU*/

#3D {
  position: fixed;
  left: -8.5em;
  top: 20px;
  width: 8em;
  background: black;
  color: white;
  margin: -4em 0 0 0;
  padding: 0.5em 0.5em 0.5em 2.5em;
  transition: 0.2s
}

#3D:hover {
  left: 0
}

#3D a {
  position: relative;
  left: 0;
  transition: 0.2s
}

#3D a:link {
  color: white;
  text-decoration: none;
}

#3D a:visited {
  color: green;
}

#3D a:hover {
  color: gray;
}

#3D a:active {
  left: -7em;
  background: black;
  color: white;
}

#3D a:focus {
  left: -7em;
  background: black;
}
<ul id="home">
  <a href="#home">PERFIL<img src="menu/home.png" style="max-width:32px; height:auto;" align="right"></a>
</ul>
<ul id="3D">
  <a href="#3D">GRAFICA 3D<img src="menu/3d.jpg" style="max-width:32px;height:auto;" align="right"></a>
</ul>

(Qazxswpoi)

html css menu slidingmenu
1个回答
0
投票

所以,你的语义似乎有点有点混乱。你应该避免内嵌的脚本和“UL”标签无“礼”内。你的CSS的策略是好的,但你是重复信息,至极不利于维护。我把你的代码放到一个更好的语义和CSS。

为了实现你的滑块,我使用的CSS变换属性。

fiddle
.wrapper * {
  overflow:hidden;
  list-style:none;
  margin:0;
  padding:0;
}
.wrapper ul li {
  display:flex;
  margin-bottom:4px;
}
.wrapper ul li a {
  background:black;
  color:white;
  padding:5px 10px;
  transform: translateX(calc(-100% + 32px));
  transition: transform 0.2s ease;
  
}
.wrapper img {
  max-width:32px;
  margin-left:5px;
}
.wrapper ul li a:hover {
  background:black;
  color:white;
  padding:5px 10px;
  transform: translateX(0);
  
}
© www.soinside.com 2019 - 2024. All rights reserved.