通过style样式实现动态显示与隐藏
2015-12-15 00:34
656 查看
今天学习了网页内容的布局与动态显示、隐藏,现把代码奉上:
<html>
<head>
<link href="./shohu.css" rel="stylesheet" type="text/css"/>
<script language="javascript">
function change(val,obj){
obj.style.backgroundColor="red";
obj.style.cursor="pointer";
if(val=="rz"){
rz.style.display="block";
zs.style.display="none";
cg.style.display="none";
}else if(val=="zs"){
rz.style.display="none";
zs.style.display="block";
cg.style.display="none";
}else if(val=="cg"){
rz.style.display="none";
zs.style.display="none";
cg.style.display="block";
}
}
function chang2(obj)
{
obj.style.backgroundColor="silver";
obj.style.cursor="auto";
}
</script>
</head>
<body>
<div class="div1">
<div class="nav1">
<ul>
<li onmouseover="change('zs',this)" onmouseout="chang2(this)">招生</li>
<li onmouseover="change('rz',this)" onmouseout="chang2(this)">热招</li>
<li onmouseover="change('cg',this)" onmouseout="chang2(this)">出国</li>
</ul>
</div>
<div id="zs" class="zs" >
<ul>
<li><a href="#">招生招生招生招生</a></li>
<li><a href="#">招生招生招生招生</a></li>
<li><a href="#">招生招生招生招生</a></li>
<li><a href="#">招生招生招生招生</a></li>
<li><a href="#">招生招生招生招生</a></li>
<li><a href="#">招生招生招生招生</a></li>
<li><a href="#">招生招生招生招生</a></li>
<li><a href="#">招生招生招生招生</a></li>
</ul>
</div>
<div id="rz" class="rz" onmouseover="change('rz')">
<ul>
<li><a href="#">热招热招热招热招</a></li>
<li><a href="#">热招热招热招热招</a></li>
<li><a href="#">热招热招热招热招</a></li>
<li><a href="#">热招热招热招热招</a></li>
<li><a href="#">热招热招热招热招</a></li>
<li><a href="#">热招热招热招热招</a></li>
<li><a href="#">热招热招热招热招</a></li>
<li><a href="#">热招热招热招热招</a></li>
</ul>
</div>
<div id="cg" class="cg" onmouseover="change('cg')">
<ul>
<li><a href="#">出国出国出国出国</a></li>
<li><a href="#">出国出国出国出国</a></li>
<li><a href="#">出国出国出国出国</a></li>
<li><a href="#">出国出国出国出国</a></li>
<li><a href="#">出国出国出国出国</a></li>
<li><a href="#">出国出国出国出国</a></li>
<li><a href="#">出国出国出国出国</a></li>
<li><a href="#">出国出国出国出国</a></li>
</ul>
</div>
</div>
</body>
</html>
2.css文件
body{
font-size:12px;
}
.div1{
width:126px;
height:156px;
background-color:pink;
}
.nav1{
width:20px;
height:156px;
float:left;
/*background-color:red;*/
padding:0px;
margin:0px;
}
.nav1 ul{
padding:0px;
margin-top:8px;
margin-left:0px;
width:20px;
height:156px;
float:left;
}
.nav1 ul li{
list-style-type:none;
width:20px;
height:40px;
float:left;
background-color:silver;
text-align:center;
padding-top:2px;
margin-top:3px;
}
.zs,.rz,.cg{
width:106px;
height:156px;
/*background-color:silver;*/
margin-left 2px;
float:left;
}
.zs ul,.rz ul,.cg ul{
padding:0px;
margin-top:6px;
margin-left:4px;
height:156px;
width:106px;
float:left;
}
.zs ul li,.rz ul li,.cg ul li{
list-style-type:none;
margin-top:0px;
width:106px;
line-height:18px;
float:left;
}
.rz{
display: none
}
.cg{
display: none
}
<html>
<head>
<link href="./shohu.css" rel="stylesheet" type="text/css"/>
<script language="javascript">
function change(val,obj){
obj.style.backgroundColor="red";
obj.style.cursor="pointer";
if(val=="rz"){
rz.style.display="block";
zs.style.display="none";
cg.style.display="none";
}else if(val=="zs"){
rz.style.display="none";
zs.style.display="block";
cg.style.display="none";
}else if(val=="cg"){
rz.style.display="none";
zs.style.display="none";
cg.style.display="block";
}
}
function chang2(obj)
{
obj.style.backgroundColor="silver";
obj.style.cursor="auto";
}
</script>
</head>
<body>
<div class="div1">
<div class="nav1">
<ul>
<li onmouseover="change('zs',this)" onmouseout="chang2(this)">招生</li>
<li onmouseover="change('rz',this)" onmouseout="chang2(this)">热招</li>
<li onmouseover="change('cg',this)" onmouseout="chang2(this)">出国</li>
</ul>
</div>
<div id="zs" class="zs" >
<ul>
<li><a href="#">招生招生招生招生</a></li>
<li><a href="#">招生招生招生招生</a></li>
<li><a href="#">招生招生招生招生</a></li>
<li><a href="#">招生招生招生招生</a></li>
<li><a href="#">招生招生招生招生</a></li>
<li><a href="#">招生招生招生招生</a></li>
<li><a href="#">招生招生招生招生</a></li>
<li><a href="#">招生招生招生招生</a></li>
</ul>
</div>
<div id="rz" class="rz" onmouseover="change('rz')">
<ul>
<li><a href="#">热招热招热招热招</a></li>
<li><a href="#">热招热招热招热招</a></li>
<li><a href="#">热招热招热招热招</a></li>
<li><a href="#">热招热招热招热招</a></li>
<li><a href="#">热招热招热招热招</a></li>
<li><a href="#">热招热招热招热招</a></li>
<li><a href="#">热招热招热招热招</a></li>
<li><a href="#">热招热招热招热招</a></li>
</ul>
</div>
<div id="cg" class="cg" onmouseover="change('cg')">
<ul>
<li><a href="#">出国出国出国出国</a></li>
<li><a href="#">出国出国出国出国</a></li>
<li><a href="#">出国出国出国出国</a></li>
<li><a href="#">出国出国出国出国</a></li>
<li><a href="#">出国出国出国出国</a></li>
<li><a href="#">出国出国出国出国</a></li>
<li><a href="#">出国出国出国出国</a></li>
<li><a href="#">出国出国出国出国</a></li>
</ul>
</div>
</div>
</body>
</html>
2.css文件
body{
font-size:12px;
}
.div1{
width:126px;
height:156px;
background-color:pink;
}
.nav1{
width:20px;
height:156px;
float:left;
/*background-color:red;*/
padding:0px;
margin:0px;
}
.nav1 ul{
padding:0px;
margin-top:8px;
margin-left:0px;
width:20px;
height:156px;
float:left;
}
.nav1 ul li{
list-style-type:none;
width:20px;
height:40px;
float:left;
background-color:silver;
text-align:center;
padding-top:2px;
margin-top:3px;
}
.zs,.rz,.cg{
width:106px;
height:156px;
/*background-color:silver;*/
margin-left 2px;
float:left;
}
.zs ul,.rz ul,.cg ul{
padding:0px;
margin-top:6px;
margin-left:4px;
height:156px;
width:106px;
float:left;
}
.zs ul li,.rz ul li,.cg ul li{
list-style-type:none;
margin-top:0px;
width:106px;
line-height:18px;
float:left;
}
.rz{
display: none
}
.cg{
display: none
}
相关文章推荐
- CSS动画之硬件加速
- 修改WordPress中文章编辑器的样式的方法详解
- css3点击涟漪效果
- dynamic-css 动态 CSS 库,使得你可以借助 MVVM 模式动态生成和更新 css,从 js 事件和 css 选择器的苦海中脱离出来
- css常用简写
- 带滑动条的导航栏(上)---CSS实现样式
- CSS3阴影 box-shadow的使用和技巧总结
- 浅谈HTML和css
- ListView子布局样式有多个的处理
- css权威指南-基本视觉格式化(水平与垂直)
- bootstarp 样式细节(tooltip布局)
- 《CSS3秘籍》第12-17章
- css3 基础
- CSS样式
- css设置文本超出两行 末尾用省略号表示
- CSS3选择器使用小结
- 用border做纯CSS的三角形
- CSS Sprites技术
- CSS的一些简单概念
- css中margin和padding的用法