【HTML+CSS】响应式导航栏2.0

源码

HTML

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="NavStyle2.css" />
		<link rel="stylesheet" type="text/css" href="https://cdn.staticfile.org/font-awesome/4.7.0/css/font-awesome.css" />
		</head>
	<body>
		<nav id="top">
			
			<div class="logo">
				<img src="pic/logo2.png" />
			</div>
			
			<div class="nav-text">
				
				<input type="checkbox" id="check" />
				<label for="check" class="checkbtn">
					<i class="fa fa-bars"></i>
				</label>
				
				
				<ul class="nav-titles">
					<li class="nav-title">
						Home
					</li>
					<li class="nav-title">
						<div class="nav-link">Project</div>
						<div class="nav-substitle">
							<a>Design</a>
							<a>Description</a>
							<a>Contribution</a>
							<a>Safety</a>
						</div>
					</li>
					<li class="nav-title">
						<div class="nav-link">Project</div>
						<div class="nav-substitle">
							<a>Design</a>
							<a>Description</a>
							<a>Contribution</a>
							<a>Safety</a>
						</div>
					</li>
					<li class="nav-title">
						<div class="nav-link">Project</div>
						<div class="nav-substitle">
							<a>Design</a>
							<a>Description</a>
							<a>Contribution</a>
							<a>Safety</a>
						</div>
					</li>
				</ul>
				
			</div>
			
		</nav>
	</body>
</html>

CSS

*{
	padding: 0;
	margin: 0;
}
#top{
	background-color: #000000;
	height: 70px;
	position: fixed;
	width: 100%;
}
.logo img{
	width: 100%;
	border-radius: 100px;
}
.logo{
	background-color: #000000;
	position: absolute;
	width: 7%;
	border-radius: 80px;
}
.nav-text{
	width: fit-content;
	margin: auto;
}
.nav-title{
	display: inline-block;
	height: 60px;
	text-align: center;
	line-height: 70px;
	width: 100px;
	color: white;
	vertical-align: top;
}
.nav-substitle{
	background-color: #353535;
	border-radius: 5px;
	line-height: 50px;
	width: 200px;
	display: none;
	opacity: 0.8;
}
.nav-substitle a{
	display: block;
	border: 3px solid transparent;
}
.nav-substitle a:hover{
	border: 3px solid white;
	transition-duration: 0.3s;
	border-radius: 5px;
	opacity: 1;
}
.nav-title:hover{
	cursor: pointer;
	border-bottom: 3px solid white;
	transition-duration: 1s;
}
.nav-link:hover ~ .nav-substitle{
	display: block;
}
.nav-substitle:hover{
	display: block;
}
.checkbtn{
	font-size: 30px;
	color: white;
	float: right;
	line-height: 70px;
	margin-right: 40px;
	cursor: pointer;
	display: none;
}
#check{
	display: none;
}
@media (max-width: 858px) {
	.checkbtn{
		display: block;
	}
	.logo{
		width: 60px;
	}
	ul{
		position: fixed;
		width: 100%;
		height: 100%;
		background: #2c3e50;
		top: 70px;
		left: -100%;
		text-align: center;
		transition: all 0.5s;
	}
	nav ul li{
		display: block;
		margin: 20px 0;
		line-height: 20px;
	}
	.nav-title{
		width: 100%;
	}
	nav ul li a{
		font-size: 20px;
	}
	.nav-substitle{
		width: 100%;
		position: relative;
		top: -5px;
	}
	#check:checked ~ ul{
		left: 0;
	}
	.nav-text{
		width: 100%;
	}
}

效果

在这里插入图片描述

在这里插入图片描述

  • 0
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值