带收缩的菜单栏

效果图
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no" />
		<style type="text/css">
			.icon {width: 1.5em; height: 1.8em;vertical-align: -0.15em;fill: currentColor;overflow: hidden;}
			.icon svg{width: 100%;height: 100%;}
			html,body{margin:0;padding:0;font-size:12px;}
			*{margin:0;padding:0;}
			ul,ol,li{list-style: none}
			@media (min-width: 768px){
				.nav-bar{position: fixed;top:0;left:0;width:250px;height: 100%;background:#44BBA3;color:#eee;overflow: hidden;transition: width .5s}
				.nav-bar .head-icon{position:relative;width:210px;height: 50px;line-height:50px;background: #fba;padding:20px;transition: all .5s}
				.nav-bar-hidden .head-icon h2{transition: opacity .5s}
				.nav-bar .head-icon .icon{position:absolute;top:20px;right:20px;width:50px;height: 50px;cursor: pointer;transition: all .5s}
				.nav-bar .menu ul{width:250px;padding-top: 20px}
				.nav-bar .menu ul li{position:relative;width:210px;height: 30px;padding:10px 20px;line-height: 30px;font-size: 16px;cursor: pointer;overflow: hidden;}
				.nav-bar .menu ul li:hover .menu-title{font-size: 18px}
				.nav-bar .menu-title{float: left;width: 160px;height: 30px;padding-left: 10px;white-space: normal;overflow: hidden;text-overflow: ellipsis;}
				.nav-bar .menu-icon{float: left;width: 30px;height: 30px;transition: all .5s}
				.nav-bar-show{width:250px;}
				.nav-bar-hidden{width: 50px;}
				.nav-bar-show .head-icon .icon{right:20px;}
				.nav-bar-hidden .head-icon h2{opacity: 0}
				.nav-bar-hidden .head-icon .icon{right:200px;}
				.nav-bar-hidden .menu-icon{margin-left: -10px}
			}
			@media (max-width: 767px){
				.nav-bar{width:100%;background:#44BBA3;color:#eee;overflow: hidden;transition: width .5s}
				.nav-bar .head-icon{position:fixed;width:90%;height: 40px;line-height:40px;font-size:20px;background: #fba;padding:20px 5%;z-index:999;transition: all .5s}
				.nav-bar .head-icon .icon{position:absolute;top:10%;right:0;width:60px;height: 60px;}
				.nav-bar .menu ul{width:100%;overflow: hidden;padding-top: 80px;transition: height .5s;}
				.nav-bar .menu ul li{display:flex;width:100%;padding:5%;font-size: 20px;overflow: hidden;border-bottom: 1px solid #ccc}
				.nav-bar .menu ul .menu-title{display:flex;align-items: center;padding-left: 5%}
				.nav-bar-show ul{height: 100%;}
				.nav-bar-hidden ul{height: 0;}
				
			}
			
		</style>
		<script src="http://at.alicdn.com/t/font_1157887_p0r26uxhb1m.js" type="text/javascript"></script>
		<!--<script src="font_symble/iconfont.js" type="text/javascript"></script>-->
	</head>
	<body>
		<div class="nav-bar nav-bar-hidden">
			<div class="head-icon">
				<h2>某某管理系统</h2>
				<svg class="icon" aria-hidden="true" id="toggle">
    				<use xlink:href="#icon-ziyuan5"></use>
				</svg>
			</div>
			<div class="menu">
				<ul>
					<li>
						<div class="menu-icon">
							<svg class="icon" aria-hidden="true">
			    				<use xlink:href="#icon-xiangshui"></use>
							</svg>
						</div>
						<div class="menu-title">菜单项</div>
					</li>
					<li>
						<div class="menu-icon">
							<svg class="icon" aria-hidden="true">
			    				<use xlink:href="#icon-fangshaishuang"></use>
							</svg>
						</div>
						<div class="menu-title">菜单项</div>
					</li>
					<li>
						<div class="menu-icon">
							<svg class="icon" aria-hidden="true">
			    				<use xlink:href="#icon-jiemaogao"></use>
							</svg>
						</div>
						<div class="menu-title">菜单项</div>
					</li>
					<li>
						<div class="menu-icon">
							<svg class="icon" aria-hidden="true">
			    				<use xlink:href="#icon-kouhong"></use>
							</svg>
						</div>
						<div class="menu-title">菜单项</div>
					</li>
					<li>
						<div class="menu-icon">
							<svg class="icon" aria-hidden="true">
			    				<use xlink:href="#icon-huazhuangshua"></use>
							</svg>
						</div>
						<div class="menu-title">菜单项</div>
					</li>
					<li>
						<div class="menu-icon">
							<svg class="icon" aria-hidden="true">
			    				<use xlink:href="#icon-yanying"></use>
							</svg>
						</div>
						<div class="menu-title">菜单项</div>
					</li>
					<li>
						<div class="menu-icon">
							<svg class="icon" aria-hidden="true">
			    				<use xlink:href="#icon-penwu"></use>
							</svg>
						</div>
						<div class="menu-title">菜单项</div>
					</li>
				</ul>
				
			</div>
		</div>
		<script type="text/javascript">
			var toggle = document.getElementById('toggle');
			var leftBar = document.getElementsByClassName('nav-bar')[0]
			toggle.onclick = function(){
				let ToggleClass = leftBar.getAttribute('class')
				if(ToggleClass.search('nav-bar-hidden') != -1){
					leftBar.setAttribute('class','nav-bar nav-bar-show')
				}else if(ToggleClass.search('nav-bar-show') != -1){
					leftBar.setAttribute('class','nav-bar nav-bar-hidden')
				}

			}
			
		</script>
	</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值