<!DOCTYPE html>
<html>
<head>
	<title>左侧导航栏</title>
	<style>
		body{
			margin: 0;
			padding: 0;
		}
		nav{
			background-color: #333;
			height: 100%;
			position: fixed;
			left: 0;
			top: 0;
			width: 200px;
			overflow: auto;
			padding-top: 20px;
		}
		nav ul{
			list-style: none;
			padding: 0;
			margin: 0;
		}
		nav li{
			padding: 10px;
			font-size: 18px;
			color: #fff;
			cursor: pointer;
			transition: all 0.3s ease;
		}
		nav li:hover{
			background-color: #555;
		}
		nav li.active{
			background-color: #4CAF50;
		}
		.main{
			margin-left: 200px;
			padding: 20px;
		}
	</style>
	<script>
		window.onload = function(){
			var navItems = document.querySelectorAll('nav li');
			for(var i=0; i<navItems.length; i++){
				navItems[i].addEventListener('click', function(){
					document.querySelector('.active').classList.remove('active');
					this.classList.add('active');
				});
			}
		}
	</script>
</head>
<body>
	<nav>
		<ul>
			<li class="active">首页</li>
			<li>新闻</li>
			<li>产品</li>
			<li>关于我们</li>
			<li>联系我们</li>
		</ul>
	</nav>
	<div class="main">
		<h1>欢迎来到我们的网站!</h1>
		<p>这是一个左侧导航栏的示例网页。</p>
	</div>
</body>
</html
使用html+css+js编写一个网页左边导航栏

原文地址: https://www.cveoy.top/t/topic/fKRf 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录