Tabelas em Zebra

Você também acha muito trabalhoso ficar colocando cor um linha sim e outra não em uma tabela? Quem sabe esta dica o ajude 😀
Image Hosted by ImageShack.us

HTML

<table align=”center” id=”default” summary=”Ejemplo de tabla”>
<caption>
Autores en InfectedFX.net
</caption>
<thead>
<tr>
<th>Nombre</th>
<th>Ocupación</th>
<th>Website</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan=”3″>Total: 4 Usuarios </td>
</tr>
</tfoot>
<tbody>
<tr>
<td>Infected-FX</td>
<td>Diseñador</td>
<td><a href=”http://www.infectedfx.net”>www</a></td&gt;
</tr>
<tr>
<td>Zetta</td>
<td>Developer</td>
<td><a href=”http://www.zetaweb.net”>www</a></td&gt;
</tr>
<tr>
<td>Zillah</td>
<td>A.I.</td>
<td><a href=”http://www.blogzillah.com”>www</a></td&gt;
</tr>
<tr>
<td>Hecgo</td>
<td>Developer</td>
<td><a href=”http://www.hecgo.com”>www</a></td&gt;
</tr>
</tbody>
</table>

CSS

#default {
border-collapse:collapse;
background-color: #E8E8E8;
width:100%;
}
#default caption{
background-color:#59819F;
border-bottom:3px solid #C2DBEF;
color:#FFF;
padding:10px;
text-transform:uppercase;
}

#default thead th{
background-color:#18394F;
border-bottom:3px solid #59819F;
color:#FFF;
padding:5px;
}

#default tbody tr td {
padding: 3px 8px;
}

#default tfoot tr td{
background-color:#59819F;
color:#FFF;
padding:4px;
text-align:center;
}

/*/////////////// TABLE DEMO GREEN //////////////////*/

#demoGreen {
border-collapse:collapse;
background-color: #E8E8E8;
width:100%;
}
#demoGreen caption{
background-color:#99CC00;
border-bottom:3px solid #669900;
color:#FFF;
padding:10px;
text-transform:uppercase;
}

#demoGreen thead th{
background-color:#333;
border-bottom:3px solid #000;
color:#FFF;
padding:5px;
}

#demoGreen tbody tr td {
padding: 3px 8px;
}

#demoGreen tfoot tr td{
background-color:#666;
color:#FFF;
padding:4px;
text-align:center;
}

/*/////////////// TABLE DEMO BLUE //////////////////*/
#demoBlue {
border-collapse:collapse;
background-color: #E8E8E8;
width:100%;
}
#demoBlue caption{
background-color:#50ADEA;
border-bottom:3px solid #1975D7;
color:#FFF;
padding:10px;
text-transform:uppercase;
}

#demoBlue thead th{
background-color:#F5F5F5;
border-bottom:3px solid #CCC;
color:#666;
padding:5px;
}

#demoBlue tbody tr td {
padding: 3px 8px;
}

#demoBlue tfoot tr td{
background-color:#E7E7E7;
color:#B7B7B7;
padding:4px;
text-align:center;
}

JavaScript

<script type=”text/javascript”>
// this function is needed to work around
// a bug in IE related to element attributes
function hasClass(obj) {
var result = false;
if (obj.getAttributeNode(“class”) != null) {
result = obj.getAttributeNode(“class”).value;
}
return result;
}

function stripe(id) {

// the flag we’ll use to keep track of
// whether the current row is odd or even
var even = false;

// if arguments are provided to specify the colours
// of the even & odd rows, then use the them;
// otherwise use the following defaults:
var evenColor = arguments[1] ? arguments[1] : “#F0F8FF”;
var oddColor = arguments[2] ? arguments[2] : “#C2DBEF”;

// obtain a reference to the desired table
// if no such table exists, abort
var table = document.getElementById(id);
if (! table) { return; }

// by definition, tables can have more than one tbody
// element, so we’ll have to get the list of child
// <tbody>s
var tbodies = table.getElementsByTagName(“tbody”);

// and iterate through them…
for (var h = 0; h < tbodies.length; h++) {

// find all the <tr> elements…
var trs = tbodies[h].getElementsByTagName(“tr”);

// … and iterate through them
for (var i = 0; i < trs.length; i++) {

// avoid rows that have a class attribute
// or backgroundColor style
if (! hasClass(trs[i]) &&
! trs[i].style.backgroundColor) {

// get all the cells in this row…
var tds = trs[i].getElementsByTagName(“td”);

// and iterate through them…
for (var j = 0; j < tds.length; j++) {

var mytd = tds[j];

// avoid cells that have a class attribute
// or backgroundColor style
if (! hasClass(mytd) &&
! mytd.style.backgroundColor) {

mytd.style.backgroundColor =
even ? evenColor : oddColor;

}
}
}
// flip from odd to even, or vice-versa
even = ! even;
}
}
}
</script>

<script type=”text/javascript”>
window.onload = function() {
stripe(‘default’);
stripe(‘demoGreen’, ‘#ECFFAF’, ‘#F3FFCF’);
stripe(‘demoBlue’, ‘#FFFFFF’, ‘#F6F6F6’);
stripe(‘demoRed’, ‘#FFEFEF’, ‘#EFC2C2’);
}
</script>

Exemplos

Fonte: http://www.infectedfx.net/

Deixe um comentário