"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
<head>
<title>鼠标移动显示</title>
<meta http-equiv="Content-Type" content="text/htmlcharset=utf-8"/>
<meta name="description" content=""/>
<script type="text/javascript" src="js/jquery-1.8.0.js"></script>
<style type="text/css">
ul,li{
margin:0px
padding:0px
list-style: none
}
ul{
height:31px
border-bottom:1px solid #f46d52
}
li{
width:100px
height:30px
border-radius:5px 5px 0px 0px
border:1px solid #ccc
border-bottom:none
text-align: center
line-height: 30px
background-color:#EEEEEE
float: left
color:black
font-weight: 800
margin-left:5px
}
li:hover{
height:31px
background-color: white
color:#FDE7D2
border:1px solid #f46d52
border-bottom:none
cursor:pointer
}
</style>
</head>
<body>
<div class="nav">
<ul>
<li>导航1</li>
<li>导航2</li>
<li>导航3</li>
</ul>
</div>
</body>
</html>
效果图:
这个只是简单的.hover事件,如果要点击得到效果那个需要写js。。。
css样式给li。1.文字居中定义文字居中始终是要的,所以首先给予ul外层div一个text-align(文本对齐:居中),还可以给一个“溢位:隐藏(overflow: hidden)”,当然也可以定义一下高和宽。
2.ul定义ul不能定义宽度,我们只能给一个定位,类型为相对(position: relative),置入左为50%(left: 50%),当然也可以给一个浮动。请注意,ul千万不能用溢位:隐藏(overflow: hidden),这样,部分li就无法显示。
3.li定义li的定义跟ul差不多,宽度不固定,同样给一个定位,类型为相对(position: relative),置入右为50%(right: 50%),恰恰和ul相反,这样定义后li就可以无论分页多少始终居中了。