<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>自适应宽度的标签导航</title>

<style>
body
{
    font-size: 14px;
    font-family: "宋体"
}

ol li { margin: 8px}

#con
{
    font-size: 12px;
    margin: 0px auto;
    width: 600px

}

#tags
{
    padding:0px;
    margin: 0px 0px 0px 10px;
    width: 400px;  
    height: 23px
}

#tags li
{
    background: url(images/tagleft.gif) no-repeat left bottom;
    float: left;
    margin-right: 1px;
    list-style-type:none;
    height: 23px
}

#tags li a
{
    padding-right: 10px;
    padding-left: 10px;
    background: url(images/tagright.gif) no-repeat right bottom;
    float: left;
    padding-bottom: 0px;
    color: #999;
    line-height: 23px;
    padding-top: 0px;
    height: 23px;
    text-decoration:none
}

#tags li.emptyTag
{
    background: none transparent scroll repeat 0% 0%;
    width: 4px
}

#tags li.selectTag
{
    background-position: left top;
    margin-bottom: -2px;
    position: relative;
    height: 25px
}

#tags li.selectTag a
{
    background-position: right top;
    color: #000;
    line-height: 25px;
    height: 25px
}

#tagContent
{
    padding: 1px;
    border: #aecbd4 1px solid;   
    background-color: #fff
}

.tagContent
{
    padding:10px;
    display: none;  
    background: url(images/bg.gif) repeat-x;
    width: 576px;
    color: #474747;
    height: 250px
}

#tagContent div.selectTag
{
    display: block
}

</style>

</head>
<body>

<div id="con">
<ul id="tags">
  <li class="selectTag"><a onMouseover="selectTag('tagContent0',this)" href="javascript:void(0)">标签一</a> </li>
  <li><a onMouseover="selectTag('tagContent1',this)" href="javascript:void(0)">标签二</a> </li>
  <li><a onMouseover="selectTag('tagContent2',this)" href="javascript:void(0)">自适应宽度的标签</a> </li>
  <li><a onMouseover="selectTag('tagContent3',this)" href="javascript:void(0)">自适应宽度</a> </li>
</ul>
<div id="tagContent">
<div class="tagContent" id="tagContent0">第一个标签的内容</div>
<div class="tagContent selectTag" id="tagContent1">第二个标签的内容</div>
<div class="tagContent" id="tagContent2">第三个标签的内容</div>
<div class="tagContent" id="tagContent3">第四个标签的内容</div>
</div>
</div>

<script>
function selectTag(showContent,selfObj){
 // 操作标签
 var tag = document.getElementById("tags").getElementsByTagName("li");
 var taglength = tag.length;
 for(i=0; i<taglength; i++){
  tag[i].className = "";
 }
 selfObj.parentNode.className = "selectTag";
 // 操作内容
 for(i=0; j=document.getElementById("tagContent"+i); i++){
  j.style.display = "none";
 }
 document.getElementById(showContent).style.display = "block";
}
</script>

</html>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  
    "http://www.w3.org/TR/html4/loose.dtd">  
    <html xmlns="http://www.w3.org/1999/xhtml">  
        <head>  
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
            <title>New Web Project</title>  
            <style type="text/css">  
                #content {  
                    width: 400px;  
                    height: 200px;  
                }  
                  
                #tab_bar {  
                    width: 400px;  
                    height: 20px;  
                    float: left;  
                }  
                #tab_bar ul {  
                    padding: 0px;  
                    margin: 0px;  
                    height: 20px;  
                    text-align: center;  
                }  
                  
                #tab_bar li {  
                    list-style-type: none;  
                    float: left;  
                    width: 133.3px;  
                    height: 20px;  
                    background-color: gray;  
                }  
                  
                .tab_css {  
                    width: 400px;  
                    height: 200px;  
                    background-color: orange;  
                    display: none;  
                    float: left;  
                }  
                  
            </style>  
            <script type="text/javascript">  
                var myclick = function(v) {  
                    var llis = document.getElementsByTagName("li");  
                    for(var i = 0; i < llis.length; i++) {  
                        var lli = llis[i];  
                        if(lli == document.getElementById("tab" + v)) {  
                            lli.style.backgroundColor = "orange";  
                        } else {  
                            lli.style.backgroundColor = "gray";  
                        }  
                    }  
      
                    var divs = document.getElementsByClassName("tab_css");  
                    for(var i = 0; i < divs.length; i++) {  
      
                        var divv = divs[i];  
      
                        if(divv == document.getElementById("tab" + v + "_content")) {  
                            divv.style.display = "block";  
                        } else {  
                            divv.style.display = "none";  
                        }  
                    }  
      
                }  
            </script>  
        </head>  
        <body>  
            <div id="content">  
                <div id="tab_bar">  
                    <ul>  
                        <li id="tab1" onclick="myclick(1)" >
                            tab1  
                        </li>  
                        <li id="tab2" onclick="myclick(2)">  
                            tab2  
                        </li>  
                        <li id="tab3" onclick="myclick(3)">  
                            tab3  
                        </li>  
                    </ul>  
                </div>  
                <div class="tab_css" id="tab1_content" style="display: block">  
                    <div>页面一</div>  
                </div>  
                <div class="tab_css" id="tab2_content" style="display: none">  
                    <div>页面二</div>  
                </div>  
                <div class="tab_css" id="tab3_content" style="display: none">  
                    <div>页面三</div>  
                </div>  
            </div>  
        </body>  
    </html>

<!DOCTYPE HTML>
<html>
<head>
<style>
.content{

float:left;
}
.tab{

list-style: none;
 
    float:left;
}

.tab-active{
    border-bottom:none;
    border-top-width: 2px;
    height: 28px;
    background:red;
    color: #333333;
    font-weight: bold;
}
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>

<ul class="tab clearfix">
    <li>标签1</li>
    <li class="tab-active">标签2</li>
    <li>标签3</li>
</ul>
<div class="content">
    <div class="inner" style="display:none">
        标签1内容
    </div>
    <div class="inner">
        标签2内容
    </div>
    <div class="inner" style="display:none">
        标签3内容
    </div>
</div>

<script type="text/javascript">
    var lists = $('.tab li');
    var contents = $('.content .inner');

function bindEvent(){

lists.each(function(index_li, li){
            $(this).on('click', function(event){

lists.removeClass('tab-active');
                $(this).addClass('tab-active');

contents.each(function(index_content, content){
                    if(index_li === index_content){
                        $(this).show();
                    }else{
                        $(this).hide();
                    }
                });
            });
        });
    }

function init(){
        bindEvent();
    }

init();
</script>

</body>
</html>

最新文章

  1. angularJS 杂
  2. SqlServer切换MySql总结
  3. Intent(一.显示使用intent)
  4. C语言调用curl库抓取网页图片(转)
  5. Scala入门学习笔记四--List使用
  6. 半径无关单核单线程最快速高斯模糊实现(附完整C代码)
  7. SVN 服务器端安装过程
  8. POJ 2891 Strange Way to Express Integers(中国剩余定理)
  9. php js表单登陆验证
  10. HDU 1272 小希的迷宫 (水题)
  11. 集合-Collection
  12. 【剑指Offer学习】【全部面试题汇总】
  13. (转)C++设计模式——观察者模式
  14. tcpdump详细用法
  15. Java面试宝典笔记录
  16. python3 发生器 迭代器 内置函数 协程 哈哈我又回来啦
  17. Elasticsearch.Net、Nest批量插入BulkAll
  18. jQuery中event.target和this的区别
  19. 2.Hibernate的主配置文件hibernate.cfg.xml
  20. 图结构练习——判断给定图是否存在合法拓扑序列(sdutoj)

热门文章

  1. NX二次开发-UFUN创建倒角UF_MODL_create_chamfer
  2. java: java中的 getInstance() 的理解
  3. SparkSession、SparkContext、SQLContext和HiveContext之间的区别。
  4. scrapy的使用--Rcrapy-Redis
  5. 连接mysql并查询
  6. sql 特殊时间值 第一天或最后一天 无计算错误
  7. batch、随机、Mini-batch梯度下降
  8. Spark与Hadoop的对比
  9. JS 实现省市联动
  10. 初识Qgis