纯css实现导航条滚动后固定和锚点导航
代码语言:html
所属分类:菜单导航
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link type="text/css" rel="stylesheet" href="http://repo.bfw.wiki/bfwrepo/css/normalize.css">
<style>
html, body {
height: 100%;
max-height: 100%;
overflow: auto;
scroll-behavior: smooth;
}
*, input {
box-sizing: border-box;
}
.site-wrapper {
padding-top: 30px;
}
.site-wrapper:before {
content: '';
display: block;
height: 10px;
width: 100%;
position: absolute;
z-index: 999;
top: 50px;
background: linear-gradient(0deg, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.1) 100%);
}
[class*="button"] {
display: block;
padding: 10px 20px;
box-shadow: inset 0 0 0 1px #005d80;
margin-left: 5px;
border-radius: 5px;
text-decoration: none;
color: #005d80;
}
[class*="button"]:hover {
color: #00baff;
box-shadow: inset 0 0 0 1px #00baff;
}
[class*="button"][class*="-prominent"] {
background-color: #005d80;
color: white;
box-shadow: none;
border: none;
}
[class*="button"][class*="-prominent"]:hover {
background-color: #00baff;
}
.login-form {
position: absolute;
top: 0;
background: white;
height: 50px;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
transform: translateY(-100px);
opacity: 0;
transition: .25s ease-in-out;
}
.login-form input {
padding: 0 10px;
height: 38px;
border: 1px solid #cccccc;
margin-left: 5px;
border-radius: 5px;
}
#show-login {
position: fixed;
transform: translateX(-4000px);
}
#show-login:checked + nav {
opacity: 0;
}
#show-login:checked ~ .login-form {
transform: translateY(0);
opacity: 1;
}
header {
position: sticky;
z-index: 1000;
top: 0;
background: white;
}
header nav {
height: 50px;
margin-bottom: 30px;
margin-left: auto;
margin-right: auto;
padding: 0 20px;
display: flex;
align-items: center;
max-width: calc(1200px + 40px);
transition: .25s ease-in-out;
}
header nav ul {
list-style-type: none;
display: flex;
padding: 0 0 0 20px;
margin: 0;
margin-right: auto;
}
header nav ul li {
margin-right: 20px;
}
header nav ul li a {
text-decoration: none;
color: #00baff;
}
header nav ul li a:hover {
text-decoration: underline;
}
header .logo {
display: block;
height: 30px;
width: 30px;
overflow: hidden;
}
header .logo .logo-mark {
display: block;
height: 30px;
width: 60px;
border: 3px solid #005d80;
border-radius: 30px;
transform: translateX(-30px);
transition: .25s ease-in-out;
}
header .logo:hover .logo-mark {
border-color: #00baff;
transform: translateX(0);
}
.cta {
text-align: center;
padding: 100px 0;
margin-bottom: -20px;
overflow: hidden;
position: relative;
}
.cta .cta-background {
position: absolute;
z-index: 0;
top: 0;
min-height: 100%;
width: 100%;
left: 0;
}
.cta h1 {
position: relative;
z-index: 1;
color: white;
text-shadow: 0 3px 3px rgba(0, 0, 0, 0.3);
}
main {
padding: 0 70px;
}
main h2 {
color: #005d80;
margin: 0;
padding-top: 70px;
}
main h2, main p {
max-width: 1200px;
margin-left: auto;
margin-right: auto;
}
footer {
margin-top: 70px;
padding: 40px;
background: rgba(0, 93, 128, 0.1);
}
footer .footer-elements {
max-width: 1200px;
margin: 0 auto;
}
</style>
</head>
<body translate="no">
<div class="site-wrapper" id="home">
<header>
<input type="checkbox" id="show-login" />
<nav class="site-nav">
<a href="#home" class="logo">
<span class="logo-mark"></span>
</a>
<ul>
<li><a href="#products">Products</a></li>
<li><a href="#pricing">Pricing</a></li>
<li><a href="#faq">FAQ</a></li>
</ul>
<label class="button" for="show-login">Log In</label>
<a href="#0" class="button-prominent">Sign Up</a>
</nav>
<form class="login-form"&.........完整代码请登录后点击上方下载按钮下载查看
网友评论0