分析一段css选择器实现TAB分页技术

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<script type="text/javascript">
	function changeState(mid)
	{
		document.getElementsByTagName("body")[0].id=mid;
		}//实现换body的id值。。
	</script>
	<style type="text/css">
	body {
	font: 100% verdana, arial, sans-serif;
	background-color: #fff;
	margin: 50px;
	}

/* begin css tabs */

	ul#tabnav { /* general settings */
	text-align: left; /* set to left, right or center */
	margin: 1em 0 1em 0; /* set margins as desired */
	font: bold 11px verdana, arial, sans-serif; /* set font as desired */
	border-bottom: 1px solid #7a96df; /* set border COLOR as desired */
	list-style-type: none;
	padding: 3px 10px 3px 10px; /* THIRD number must change with respect to padding-top (X) below */
	}

	ul#tabnav li { /* do not change */
	display: inline;
	}

//1.这里运用选择器,id为tab1的body下面的li中class为tab1的现实样式为下面定义的

	body#tab1 li.tab1, body#tab2 li.tab2, body#tab3 li.tab3, body#tab4 li.tab4 { /* settings for selected tab */
	border-bottom: 1px solid #fff; /* set border color to page background color */
	background-color: #fff; /* set background color to match above border color */
	}

//2.这里运用选择器,id为tab1的body下面的li中class为tab1的现实样式为下面定义的
//这两个显示时用来制造“选中”效果


	body#tab1 li.tab1 a, body#tab2 li.tab2 a, body#tab3 li.tab3 a, body#tab4 li.tab4 a { /* settings for selected tab link */
	background-color: #fff; /* set selected tab background color as desired */
	color: #000; /* set selected tab link color as desired */
	position: relative;
	top: 1px;
	padding-top: 4px; /* must change with respect to padding (X) above and below */
	}

	ul#tabnav li a { /* settings for all tab links */
	padding: 3px 4px; /* set padding (tab size) as desired; FIRST number must change with respect to padding-top (X) above */
	border: 1px solid #7a96df; /* set border COLOR as desired; usually matches border color specified in #tabnav */
	background-color: #d4e6ef; /* set unselected tab background color as desired */
	color: #666; /* set unselected tab link color as desired */
	margin-right: 0px; /* set additional spacing between tabs as desired */
	text-decoration: none;
	border-bottom: none;
	}
	
	ul#tabnav a:hover { /* settings for hover effect */
	background: #fff; /* set desired hover color */
	}
	
/* end css tabs */
	
</style>
</head>

<body id="tab1">
//这个是关键,这个tab1让tab1的显示好像被选中了一样。可以用js修改body的id为tab2或tab3.。。实现选中显示。。(看上面的css)

<ul id="tabnav">
	<li class="tab1"><a href="tab.html" target="showdiv" onclick="changeState('tab1')">Tab One</a></li>
		<li class="tab2"><a href="tab.jsp" target="showdiv" onclick="changeState('tab2')">Tab Two</a></li>
		<li class="tab3"><a href="tab.jsp" target="showdiv" onclick="changeState('tab3')">Tab Three</a></li>
		<li class="tab4"><a href="tab.jsp" target="showdiv" onclick="changeState('tab4')">Tab Four</a></li></ul>

</body>
 	<iframe width="100%" border="0" frameborder="0" scrolling="no" id="showdiv" name="showdiv" src="tab.html"></iframe>
</html>

相关推荐