css箭头菜单

最近公司要对已有的产品进行升级,希望改变一下导航菜单的展现方式。于是,在网上搜索了一下,感觉带箭头的导航菜单方式不错,于是就模仿着写了一个,其实很简单。不废话了,看代码。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="jquery.js"></script>
<title>Menu</title>


<style type="text/css">
ul, li { 
	list-style-type:none; 
	padding:0; 
	margin:0; 
} 

#menu { 
	border:1px solid #dedede; 
	height:35px; 
	background:url(bg_out.gif) repeat-x;
} 

#menu li { 
	float:left; 
	line-height:35px; 
	padding-left: 10px;
	padding-right: 15px;
} 

#menu li div {
	height: 100%;
	width: 100%;
}

.li_out {
	background:url(arrow_out.gif) no-repeat right center;
}

.li_over {
	cursor:hand;
	background:url(arrow_over.gif) no-repeat right center;
	color:white;
}

.div_over {
	background: url(bg_over.gif) repeat-x;
	margin-left: -10px;
	padding-left: 10px;
}
</style>
<script type="text/javascript">
	$(document).ready(function(){
		$("#menu").children("li").hover(
			function(){
				$(this).addClass("li_over");
				$(this).children("div").addClass("div_over");
			},
			function(){
				$(this).removeClass("li_over");
				$(this).children("div").removeClass("div_over");
			}
		);
	});
</script>

</head>

<body>

	<ul id="menu"> 
		<li class="li_out"><div>Home</div></li> 
		<li class="li_out"><div>Equipment File</div></li> 
		<li class="li_out"><div>Sparepart Account</div></li> 
		<li class="li_out"><div>Maintenance Management</div></li> 
		<li class="li_out"><div>System</div></li> 
	</ul>


</body>
</html>

 

 效果显示如下:


 
 附件中是整个实现的代码。

 

 

2011-01-08修改:

今天和同事交流了一下,发现了更好的实现效果。感谢同事marker提出的建议和改进的帮助。

 

箭头样式导航菜单2.rar是marker提供的实现效果(注意,菜单栏在浏览器中是右对齐的),如图


箭头样式导航菜单3.rar是我改进后的另一种实现效果(注意,菜单栏在浏览器中是左对齐的),如图


大家给看看,是否还有bug没有测试到?欢迎指出,在此先谢谢!

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果你需要展示一个下拉菜单,并且需要在箭头图标上添加点击事件来展示或隐藏下拉菜单,你可以使用`uniapp`的`v-show`指令和`<transition>`组件来实现。 以下是一个简单的示例代码: ```html <template> <view class="container"> <view class="select" @tap="toggleMenu"> <text>{{ selected }}</text> <image class="arrow" :src="arrowIcon"></image> </view> <transition> <view v-show="menuVisible" class="menu"> <view class="menu-item" v-for="(item, index) in options" :key="index" @tap="selectItem(index)">{{ item }}</view> </view> </transition> </view> </template> <script> export default { data() { return { selected: '请选择', options: ['选项1', '选项2', '选项3'], menuVisible: false, arrowIcon: 'static/images/arrow-down.png' } }, methods: { toggleMenu() { this.menuVisible = !this.menuVisible; if (this.menuVisible) { this.arrowIcon = 'static/images/arrow-up.png'; } else { this.arrowIcon = 'static/images/arrow-down.png'; } }, selectItem(index) { this.selected = this.options[index]; this.menuVisible = false; this.arrowIcon = 'static/images/arrow-down.png'; } } } </script> <style> .container { position: relative; height: 100vh; } .select { display: flex; justify-content: space-between; align-items: center; padding: 10px 20px; border: 1px solid #ccc; border-radius: 20px; } .arrow { width: 20px; height: 20px; transform: rotate(0deg); transition: transform 0.3s; } .arrow.up { transform: rotate(180deg); } .menu { position: absolute; top: 60px; left: 0; width: 100%; background-color: #fff; border: 1px solid #ccc; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3); } .menu-item { height: 50px; line-height: 50px; text-align: center; font-size: 16px; border-bottom: 1px solid #ccc; } </style> ``` 在上述代码中,我们使用了一个`<view>`标签作为下拉菜单的外部容器,并在容器内部使用了一个`<view>`标签作为选择器,并在选择器中添加了一个箭头图标。在箭头图标的`@tap`事件中,我们触发`toggleMenu`方法,用来展示或隐藏下拉菜单。 我们使用了`v-show`指令来控制下拉菜单的显示和隐藏。当`menuVisible`属性为`true`时,下拉菜单会显示,否则会隐藏。在`toggleMenu`方法中,我们将`menuVisible`属性取反,用来切换下拉菜单的显示和隐藏。 我们使用了`<transition>`组件来为下拉菜单添加过渡动画。在下拉菜单中,我们使用了`v-for`指令来循环渲染下拉菜单中的选项,并在选项的`@tap`事件中触发`selectItem`方法,用来选择选项。 在CSS中,我们使用了`transform`属性来旋转箭头图标,并使用`transition`属性来添加动画效果。我们还使用了`position: absolute`属性来使下拉菜单与选择器定位。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值