PC6下载站

分类分类

CSS如何隔行换色的实现

关注+2009-12-16作者:

 网页设计中我们经常会碰到用CSS(层叠样式表)实现隔行换色的需求,您可以根据您的需要,采用下面的任何一种方法,当然要注意适合你的具体编码与需求情况。

  一、使用background背景图片

  如果行高固定的话,推荐使用隔行换色的背景图,也推荐将行高固定,这样可以兼容一切浏览器

  二、CSS Expression

  文字:color:expression(this.sourceIndex%2 ? '#ff0000':'#000000');

  背景:background-color:expression(this.sourceIndex%2 ? '#ff0000':'#000000');

  注意:本方法浏览器兼容度不够,不支持FF3。

  三、class分别定义

  <ul>

  <li class="bgcolor">...

  <li>...

  <li class="bgcolor">...

  <li>...

  </ul>

  实实在在的写法。

  四、通过JS

  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

  <html xmlns="http://www.w3.org/1999/xhtml">

  <head>

  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  <title>www.webjx.com - 四种实现CSS隔行换色的方法</title>

  <link href="index.css" rel="stylesheet" type="text/css" />

  <script type="text/javascript">

  function bgChange(){

  if(!document.getElementsByTagName) return false;

  var tables = document.getElementsByTagName("table");

  for(var i=0; i<tables.length; i++){

  var odd = false;

  trs = tables[i].getElementsByTagName("tr");

  for(var j=0; j<trs.length; j++){

  if(odd==true){

  trs[j].style.background = "#ccc";

  odd = false;

  }else{

  odd = true;

  }

  }

  }

  }

  window.onload = bgChange;

  </script>

  </head>

  <body   >

  <table width="600" border="0" align="center" cellpadding="0" cellspacing="0">

  <tr>

  <td>测试文字</td>

  <td>测试文字</td>

  <td>测试文字</td>

  </tr>

  <tr>

展开全部

相关文章

更多+相同厂商

热门推荐

  • 最新排行
  • 最热排行
  • 评分最高
排行榜

    点击查看更多

      点击查看更多

        点击查看更多

        说两句网友评论

          我要评论...
          取消