纯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;
.........完整代码请登录后点击上方下载按钮下载查看
网友评论0