div+css实现自适应响应式多屏多级菜单落地页代码

代码语言:html

所属分类:响应式

代码描述:div+css实现自适应响应式多屏多级菜单落地页代码

代码标签: div css 自适应 响应式 多屏 多级 菜单 落地页 代码

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

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

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



<link type="text/css" rel="stylesheet" href="//repo.bfw.wiki/bfwrepo/css/all.6.4.0.css">
  
<style>
@import url("https://fonts.googleapis.com/css2?family=Montserrat:wght@100..900&display=swap");
:root {
  --hue: 200;
  --sat: 5%;
}

* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}

body {
  font-family: "Montserrat", sans-serif;
}

ul {
  list-style: none;
}

a {
  text-decoration: none;
}

header {
  position: sticky;
  top: 0px;
  background-color: hsl(var(--hue), var(--sat), 98%);
  width: 100%;
  z-index: 1000;
}

section {
  position: relative;
  height: calc(100vh - 3rem);
  width: 100%;
  background: url("//repo.bfw.wiki/bfwrepo/image/634f7204e1e20.png") no-repeat top center/cover;
  overflow: hidden;
}

.overlay {
  position: absolute;
  inset: 0;
  background-color: hsl(var(--hue), var(--sat), 58%, 0.5);
}

.content {
  position: relative;
  display: grid;
  place-items: center;
  height: 100%;
  font-size: clamp(2rem, 10vw + 1rem, 5rem);
  color: hsl(var(--hue), var(--sat), 95%);
}

.container {
  max-width: 65rem;
  padding: 0 2rem;
  margin: 0 auto;
  display: flex;
  position: relative;
}

.logo-container {
  flex: 1;
  display: flex;
  align-items: center;
}

.nav-ctn {
  flex: 3;
  display: flex;
}

nav {
  flex: 2;
}

.log-sign {
  display: flex;
  justify-content: center;
  align-items: center;
  flex: 1;
}

.logo {
  color: hsl(var(--hue), 4%, 58%, 0.9);
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
  line-height: 3rem;
}

.logo span {
  font-weight: 300;
}

.btn {
  display: inline-block;
  padding: 0.5rem 1.3rem;
  font-size: 0.8rem;
  border: 2px solid #fff;
  border-radius: 2rem;
  line-height: 1;
  margin: 0 0.2rem;
  transition: 0.3s;
  text-transform: uppercase;
}

.btn.solid, .btn.transparent:hover {
  background-color: hsl(var(--hue), calc(100% - var(--sat)), 99%);
  color: hsl(var(--hue), 4%, 28%, 0.8);
}

.btn.transparent, .btn.solid:hover {
  background-color: transparent;
  color: hsl(var(--hue), var(--sat), 9%, 0.8);
}

nav > ul {
  display: flex;
  justify-content: center;
  align-items: center;
}

.nav-link {
  position: relative;
}

.nav-link > a {
  line-height: 3rem;
  color: hsl(var(--hue), var(--sat), 39%, 0.9);
  padding: 0 0.8rem;
  letter-spacing: 1px;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: 0.5s;
}

.nav-link > a > i {
  margin-left: 0.2rem;
}

.nav-link:hover > a {
  transform: scale(1.1);
}

.dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  width: 10rem;
  transform: translateY(10px);
  opacity: 0;
  pointer-events: none;
  transition: 0.5s;
}

.dropdown ul {
  position: relative;
}

.dropdown-link > a {
  display: flex;
  background-color: hsl(var(--hue), var(--sat), 89%, 0.9);
  color: hsl(var(--hue), var(--sat), 39%, 0.9);
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  align-items: center;
  justify-content: space-between;
  transition: 0.3s;
}

.dropdown-link:hover > a {
  background-color: hsl(var(--hue), var(--sat), 39%, 0.9);
  color: hsl(var(--hue), var(--sat), 89%, 0.9);
}

.dropdown-link:not(:nth-last-child(2)) {
  border-bottom: 1px solid hsl(var(--hue), var(--sat), 89%, 0.1);
}

.dropdown-link i {
  transform: rotate(-90deg);
}

.arrow {
  position: absolute;
  width: 11px;
  height: 11px;
  top: -5.5px;
  left: 32px;
  background-color: hsl(var(--hue), var(--sat), 89%, 0.9);
  transform: rotate(45deg);
  cursor: pointer;
  transition: 0.3s;
  z-index: -1;
}

.fas {
  opacity: 0.3;
}

.dropdown-link:first-child:hover ~ .arrow {
  background-color: hsl(var(--hue), var(--sat), 39%, 0.9);
}

.dropdown-link {
  position: relative;
}

.dropdown.second {
  top: 0;
  left: 100%;
  padding-left: 0.8rem;
  cursor: pointer;
  transform: translateX(10px);
}

.dropdown.second .arrow {
  top: 10px;
  left: -5.5px;
}

.nav-link:hover > .dropdown,
.dropdown-link:hover > .dropdown {
  transform: translate(0, 0);
  opacity: 1;
  pointer-events: auto;
}

.hamburger-menu-container {
  flex: 1;
  display: none;
  align-items: center;
  justify-content: flex-end;
}

.hamburger-menu {
  width: 2.5rem;
  height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.hamburger-menu div {
  width: 1.6rem;
  height: 3px;
  border-radius: 3px;
  background-color: hsl(var(--hue), var(--sat), 39%, 0.9);
  position: relative;
  z-index: 1001;
  transition: 0.5s;
}

.hamburger-menu div:before,
.hamburger-menu div:after {
  content: "";
  position: absolute;
  width: inherit;
  height: inherit;
  background-color: hsl(var(--hue), var(--sat), 39%, 0.9);
  border-radius: 3px;
  transition: 0.5s;
}

.hamburger-menu div:before {
  transform: translateY(-7px);
}

.hamburger-menu div:after {
  transform: translateY(7px);
}

#toggle-ham {
  position: absolute;
  top: 50%;
  right: 1.5rem;
  transform: translateY(-50%);
  width: 2.5rem;
  height: 2.5rem;
  z-index: 90000;
  cursor: pointer;
  opacity: 0;
  display: none;
}

#toggle-ham:checked ~ .hamburger-menu-container .hamburger-menu div {
  background-color: transparent;
}

#toggle-ham:checked ~ .hamburger-menu-container .hamburger-menu div:before {
  transform: translateY(0) rotate(-45deg);
}

#toggle-ham:checked ~ .hamburger-menu-container .hamburger-menu div:after {
  transform: translateY(0) rotate(45deg);
}

@keyframes animation {
  from {
    opacity: 0;
    transform: translateY(15px);
  }
  to {
    opacity: 1;
    transform: translateY(0px);
  }
}
@media (max-width: 820px) {
  .hamburger-menu-container {
    display: flex;
  }

  #toggle-ham {
    display: block;
  }

  .nav-ctn {
    position: fixed;
    height: calc(100vh - 3rem);
    top: 3rem;
    left: 0;
    width: 100%;
    background-color: hsl(var(--hue), var(--sat), 79%, 0.9);
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    overflow-x: hidden;
    overflow-y: auto;
    transform: translateX(100%);
    transition: 0.65s;
  }

  #toggle-ham:checked ~ .nav-ctn {
    transform: translateX(0);
  }

  #toggle-ham:checked ~ .nav-ctn .nav-link,
#toggle-ham:checked ~ .nav-ctn .log-sign {
    animation: animation 0.5s ease forwards var(--i);
  }

  nav {
    flex: initial;
    width: 100%;
  }

  nav > ul {
    flex-direction: column;
  }

  .nav-link {
    width: 100%;
    opacity: 0;
    transform: translateY(15px);
  }

  .nav-link > a {
    line-height: 1;
    padding: 1.6rem 2rem;
  }

  .nav-link:hover > a {
    transform: scale(1);
    background-color: hsl(var(--hue), var(--sat), 39%, 0.9);
    color: hsl(var(--hue), var(--sat), 89%, 0.9);
  }

  .dropdown, .dropdown.second {
    position: initial;
    top: initial;
    left: initial;
    transform: initial;
    opacity: 1;
    pointer-events: auto;
    width: 100%;
    padding: 0;
    background-color: hsl(var(--hue), var(--sat), 29%, 0.9);
    display: none;
  }

  .nav-link:hover > .dropdown,
.dropdown-link:hover > .dropdown {
    display: block;
  }

  .nav-link:hover > a > i,
.dropdown-link:hover > a > i {
    transform: rotate(360deg);
  }
.........完整代码请登录后点击上方下载按钮下载查看

网友评论0