jquery+css实现自适应响应式网站头部下拉菜单效果代码

代码语言:html

所属分类:菜单导航

代码描述:jquery+css实现自适应响应式网站头部下拉菜单效果代码

代码标签: 适应 响应 网站 头部 下拉菜单 效果

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

<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<style>
    /* Extra */
body {
  background: #ccc;
  color: #272727;
  font-size: 14px;
  margin: 0;
}

.logo {
  max-width: 200px;
}

.navbar {
  align-items: center;
  background: #fff;
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: row;
  font-family: sans-serif;
  padding: 10px 50px;
}

.push-left {
  margin-left: auto;
}

/* Menu */
.hamburger {
  background: transparent;
  border: none;
  cursor: pointer;
  display: none;
  outline: none;
  height: 30px;
  position: relative;
  width: 30px;
  z-index: 1000;
}
@media screen and (max-width: 768px) {
  .hamburger {
    display: inline-block;
  }
}
.hamburger-line {
  background: #272727;
  height: 3px;
  position: absolute;
  left: 0;
  transition: all 0.2s ease-out;
  width: 100%;
}
.hamburger:hover .hamburger-line {
  background: #777;
}
.hamburger-line-top {
  top: 3px;
}
.menu-active .hamburger-line-top {
  top: 50%;
  transform: rotate(45deg) translatey(-50%);
}
.hamburger-line-middle {
  top: 50%;
  transform: translatey(-50%);
}
.menu-active .hamburger-line-middle {
  left: 50%;
  opacity: 0;
  width: 0;
}
.hamburger-line-bottom {
  bottom: 3px;
}
.menu-active .hamburger-line-bottom {
  bottom: 50%;
  transform: rotate(-45deg) translatey(50%);
}

.nav-menu {
  display: flex;
  list-style: none;
  margin: 0;
  padding: 0;
  transition: all 0.25s ease-in;
}
@media screen and (max-width: 768px) {
  .nav-menu {
    background: #fff;
    flex-direction: column;
    justify-content: center;
    opacity: 0;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    transform: translatey(-100%);
    text-align: center;
  }
  .menu-active .nav-menu {
    transform: translatey(0%);
    opacity: 1;
  }
}
.nav-menu .menu-item a {
  color: #444444;
  display: block;
  line-height: 30px;
  margin: 0px 30px;
  text-decoration: none;
  text-transform: uppercase;
}
.nav-menu .menu-item a:hover {
  color: #777777;
  text-decoration: underline;
}
@media screen and (max-width: 768px) {
  .nav-menu .menu-item a {
    font-size: 20px;
    margin: 8px;
  }
}

.sub-nav {
  border: 1px solid #ccc;
  display: none;
  position: absolute;
  background-color: #fff;
  padding: 5px 5px;
  list-style: none;
  width: 230px;
}
@media screen and (max-width: 768px) {
  .sub-nav {
    position: relative;
    width: 100%;
    display: none;
    background-color: rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
  }
}

.nav__link:hover + .sub-nav {
  display: block;
}

.sub-nav:hover {
  .........完整代码请登录后点击上方下载按钮下载查看

网友评论0