如何创建:侧边导航按钮

学习如何使用 CSS 创建可悬停的侧边导航按钮。

جربها بنفسك

如何创建可悬停的侧边导航

第一步 - 添加 HTML:

<div id="mySidenav" class="sidenav">
  <a href="#" id="about">About</a>
  <a href="#" id="blog">Blog</a>
  <a href="#" id="projects">Projects</a>
  <a href="#" id="contact">Contact</a>
</div>

第二步 - 添加 CSS:

/* Set the style of the links inside the side navigation */
#mySidenav a {
  position: absolute; /* Position them relative to the browser window */
  left: -80px; /* Position them outside the screen */
  transition: 0.3s; /* Add transition effect when the mouse hovers */
  padding: 15px; /* 15px padding */
  width: 100px; /* Set specific width */
  text-decoration: none; /* Remove underline */
  font-size: 20px; /* Increase font size */
  color: white; /* Set text color to white */
  border-radius: 0 5px 5px 0; /* rounded corners on the top right and bottom right */
}
#mySidenav a:hover {
  left: 0; /* When the mouse hovers, make the element display as it should */
}
/* about link: 20px from the top, green background */
#about {
  top: 20px;
  background-color: #04AA6D;
}
#blog {
  top: 80px;
  background-color: #2196F3; /* blue */
}
#projects {
  top: 140px;
  background-color: #f44336; /* red */
}
#contact {
  top: 200px;
  background-color: #555 /* shallower black */
}

جربها بنفسك

الصفحات ذات الصلة

دليل:شريط التوجيه CSS