我是FE,也是Fe

          前端來源于不斷的點(diǎn)滴積累。我一直在努力。

          統(tǒng)計(jì)

          留言簿(15)

          閱讀排行榜

          評(píng)論排行榜

          google chrome瀏覽器頁簽的css實(shí)現(xiàn)


          Google Chrome瀏覽器的頁簽比較特別的是激活頁簽?zāi)?#8220;吃”掉旁邊非激活頁簽的一部分。這對(duì)css提出了一些挑戰(zhàn)。如下圖:

          當(dāng)然,要求是只能使用兩張圖,寬度自適應(yīng),用到的圖:
          正常頁簽背景:
          激活頁簽背景:
          代碼:
          <!DOCTYPE HTML>
          <head>
              
          <title>google chrome tab</title>
              
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
          <style type="text/css">
              
          /*simple reset*/
              *
          {padding:0px;margin:0px;}
              
          /*clearfix*/
              .clearfix:after 
          {content: ".";display: block;height: 0;clear: both;visibility: hidden;}
              .clearfix 
          {display: inline-block;}  /* for IE/Mac */

              
              #tab 
          { font-size:12px;margin-left:40px;_margin-left:60px;}/*由于li有margin-left:-15px;所以tab的margin-left>15px;*/
              
          /*margin-left:-15px; 讓當(dāng)前元素“縮進(jìn)”到前一個(gè)元素的右側(cè)*/
              #tab  li
          {float:left; display:block; height:26px;position:relative;margin-left:-15px;_margin-left:-30px;z-index:1;}
              #tab  li a
          {color:#000; text-decoration:none; display:block;_float:left;_position:relative;_left:15px; height:26px;padding-left:30px;padding-right:15px; line-height:26px;margin-right:15px; background:url(normal.gif) no-repeat left top;}
              
          /*i置于右邊*/
              #tab li i
          {position:absolute; right:0px;top:0px; width:15px;height:26px; z-index:3;background:url(normal.gif) no-repeat right top;}

              
          /*當(dāng)前激活的li在非激活之上(z-index)*/
              #tab  .active
          {z-index:2;top:1px; }
              #tab  .active a
          {background:url(active.gif) no-repeat left top; }
              #tab  .active i
          {background:url(active.gif) no-repeat -197px top;}
              .content
          {clear:both;border:solid 1px #bcc5d1;}

          </style>
          </head>
          <body>
          <ul id="tab">
              
          <li><href="###">頁簽1</a><i></i></li>
              
          <li class="active"><href="###">頁簽頁簽頁簽頁簽2</a><i></i></li>
              
          <li><href="###">頁簽3</a><i></i></li>
          </ul>
          <div id="" class="content">
              content
          </div>
          <script type="text/javascript">
              
          //添加事件
               var addHandler = window.addEventListener?
              
          function(elem,event,handler){elem.addEventListener(event,handler,false);}:
              
          function(elem,event,handler){elem.attachEvent("on"+event,handler);};

              
          //實(shí)現(xiàn).active切換
              addHandler(window,"load",function(){
                  
          var arrLi = document.getElementById("tab").getElementsByTagName("li");
                  
          for (var i=0,l=arrLi.length;i<l ;i++ ){
                      (
          function(index){
                          addHandler(arrLi[index],
          "click",function(e){
                              
          var evt = (window.event||e),cur=evt.target||evt.srcElement;
                              
                              
          for (var j=0,jl=arrLi.length;j<jl ;j++ ){
                                  arrLi[j].className
          ="";
                              }
                              ((cur.tagName.toLowerCase()
          =="a")?cur.parentNode:cur).className="active";
                              
          try{cur.blur();cur.parentNode.blur();}catch(e){}
                          });
                      })(i);
                  }
              });
          </script>
          </body>
          </html>


          代碼下載:下載 下載(修改后)






          posted on 2011-05-19 17:30 衡鋒 閱讀(1933) 評(píng)論(2)  編輯  收藏 所屬分類: Web開發(fā)

          評(píng)論

          # re: google chrome瀏覽器頁簽的css實(shí)現(xiàn) 2011-05-19 17:37 陽衡鋒

          IE6 下貌似有問題。有時(shí)間修復(fù)。先記著。  回復(fù)  更多評(píng)論   

          # re: google chrome瀏覽器頁簽的css實(shí)現(xiàn) 2011-05-24 09:35 楊文勝

          呵呵  回復(fù)  更多評(píng)論   

          主站蜘蛛池模板: 莎车县| 酉阳| 衢州市| 泰顺县| 东明县| 长葛市| 罗定市| 连城县| 漾濞| 海丰县| 永春县| 洪雅县| 诏安县| 右玉县| 八宿县| 松江区| 华宁县| 土默特左旗| 大邑县| 灵寿县| 漳州市| 措美县| 闵行区| 德庆县| 贵南县| 沙湾县| 牙克石市| 武鸣县| 纳雍县| 祁连县| 镇宁| 竹北市| 临洮县| 渭南市| 景洪市| 固始县| 壶关县| 中宁县| 衡东县| 井冈山市| 华容县|