/    Sign up×
Community /Pin to ProfileBookmark

odd and even rows in table with different backgrounds

trying to get have odd and even rows in the table with different colors. But not getting it. what am I missing here?

table.smallTable {
width: 300px;
font: 11px arial, helvetica, sans-serif;
border-collapse: collapse;
border: solid 2px black;
}
table.smallTable td, .smallTable th {
border: solid 1px black;
padding: 2px 9px;
}
table.smallTable th {
text-align: left;
font-weight: bold;
width: 50%;
background-color: #3CB371;
color: white;
}
table.smallTable tr.even {
background-color: #EEE;
}
table.smallTable tr.odd {
background-color: white;
}
table.smallTable tr.tableRowEven{
background-color: #EEE;
}

Thanks.

to post a comment
CSS

3 Comments(s)

Copy linkTweet thisAlerts:
@UltimaterNov 30.2005 — Looks fine to me, did you use valid HTML?
Copy linkTweet thisAlerts:
@toicontienNov 30.2005 — Piece of cake.

[code=html]
<style type="text/css" media="screen">
.smallTable td {
background-color: #fff;
}

.smallTable tr.even td {
background-color: #ccc;
}
</style>
</head>
<body>
<table>
<tbody>
<tr>
<td>Foo</td>
</tr>
<tr class="even">
<td>Foo</td>
</tr>
</tbody>
</table>
[/code]


EDIT: I think the issue with your code is that you're trying to apply a background color to the TR tag. I've tried coloring table rows before to no avail, but it always works on the TD tags.
Copy linkTweet thisAlerts:
@UltimaterNov 30.2005 — You can apply colors to the TRs to effect all the TDs:

(tested in Firefox and IE)
<i>
</i>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd"&gt;
&lt;html dir="ltr" lang="en"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;
&lt;meta http-equiv="Content-Style-Type" content="text/css"&gt;
&lt;meta http-equiv="Content-Script-Type" content="text/javascript"&gt;
&lt;style type="text/css"&gt;
body{font:1.2em arial,sans-serif;direction:ltr;margin:0;background-color:white;color:black;}
table{padding:0;margin:0;}
table.smallTable tr.even{background-color: rgb(238,238,238);color:black;}
table.smallTable tr.odd{background-color:white;color:black;}
&lt;/style&gt;
&lt;title&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;table class="smallTable"&gt;
&lt;colgroup span="4"&gt;
&lt;col width="60"&gt;
&lt;col width="60"&gt;
&lt;col width="60"&gt;
&lt;col width="60"&gt;
&lt;/colgroup&gt;
&lt;tbody&gt;
&lt;tr class="even"&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class="odd"&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class="even"&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class="odd"&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;
×

Success!

Help @Rxyz spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...