css+js实现下拉选择导航条效果代码

代码语言:html

所属分类:菜单导航

代码描述:css+js实现下拉选择导航条效果代码

代码标签: css js 下拉 选择 导航条

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  


<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500&display=swap" rel="stylesheet">


  
  
<style>
body {
  min-height: 100dvh;
  background: #fbfbfd;
  font-family: 'Inter', sans-serif;
}
body a {
  color: inherit;
  text-decoration: none;
}
body h1 {
  font: inherit;
  margin: 0;
}
body header {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: #fff;
  border-bottom: 1px solid #eaedf3;
}
body header #identity {
  position: relative;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  padding-left: 1.5rem;
  margin-right: 1px;
}
body header #identity:after {
  content: '';
  position: absolute;
  right: -1px;
  top: 25%;
  bottom: 25%;
  width: 1px;
  background: #eaedf3;
}
body header #identity img {
  height: 1.5rem;
  aspect-ratio: 1;
}
body header #identity h1 {
  line-height: 2.25rem;
  font-weight: 500;
}
body header nav {
  --width: 5.25rem;
  --height: 2.25rem;
  width: var(--width);
  height: var(--height);
}
body header nav .container {
  position: absolute;
  display: grid;
  grid-template-columns: var(--width) 0fr;
  grid-template-rows: var(--height) 0fr;
  border: 1px solid #eaedf3;
  border-radius: 0.5rem;
  background: #fff;
  color: #444;
}
body header nav .container:not(.no_animate) {
  transition: all 0.25s 0.25s, grid-template-columns 0.25s 0.25s, grid-template-rows 0.25s;
  transition: all 0.25s 0.25s, grid-template-columns 0.25s 0.25s, grid-template-rows 0.25s, -ms-grid-columns 0.25s 0.25s, -ms-grid-rows 0.25s;
}
body header nav .container * {
  transition: all 0.25s 0.25s;
}
body header nav .container button,
body header nav .container ul {
  grid-column: span 2;
}
body header nav .container button {
  -webkit-appearance: none;
     -moz-appearance: none;
          appearance: none;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  padding: 0 1rem;
  text-align: left;
  transition: 0.25s -0.1s;
}
body header nav .container button:before,
body header nav .container button:after {
  content: '';
  position: absolute;
  top: 1.125rem;
  right: 1rem;
  transform: translate(-50%, -50%);
  height: 2px;
  width: 0.5rem;
  border-radius: 1px;
  background: currentcolor;
  transition: transform 0.25s;
}
body header nav .container button:before {
  transform: translate(-50%, -50%) rotate(45deg);
}
body header nav .container button:after {
  right: 0.7rem;
  transform: translate(-50%, -50%) rotate(-45deg);
}
body header nav .container button:hover {
  color: #000;
}
body header nav .container ul {
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
  margin: 0;
}
body header nav .container ul:before {
  content: '';
  position: absolute;
  right: 1rem;
  top: 0;
  left: 1rem;
  height: 1px;
  background: #cecfd2;
  transition: background 0.25s 0.25s;
}
body header nav .container ul li {
  list-style: none;
  white-space: pre;
  margin: 0 0.5rem;
}
body header nav .container ul li:first-child {
  margin-top: 0.5rem;
}
body header nav .container ul li:last-child {
  margin-bottom: 0.5rem;
}
body header nav .container ul li a {
  display: block;
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  transition: all 0.25s -0.1s;
}
body header nav .container ul li a:hover {
  color: #000;
  background: #eaedf3;
}
body header nav .container:hover button,
body header nav .container.open button {
  color: #000;
}
body header nav .container.open {
  grid-template-columns: var(--width) 1fr;
  grid-template-rows: var(--height) 1fr;
  border-color: #cecfd2;
}
body header nav .container.open:not(.no_animate) {
  transition: all 0.25s, grid-template-columns 0.25s, grid-template-rows 0.25s 0.25s;
  transition: all 0.25s, grid-template-columns 0.25s, grid-template-rows 0.25s 0.25s, -ms-grid-columns 0.25s, -ms-grid-rows 0.25s 0.25s;
}
body header nav .container.open * {
  transition: all 0.25s;
}
b.........完整代码请登录后点击上方下载按钮下载查看

网友评论0