Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to control row color within a HTML table for the header row using CSS

Posted on 2007-11-25
3
Medium Priority
?
803 Views
Last Modified: 2012-06-22
I am new to the CSS arena and would like to know how to control the color of the first row of a <table> so that it is a different color than then the remainder of the rows. For example:

<table>
<tr bgcolor="steelblue">
</tr>
</table>

Without using the bgcolor (which I have been told is "old school") how do I accomplish this effect?
0
Comment
Question by:lonekawboy
3 Comments
 
LVL 12

Expert Comment

by:Rok-Kralj
ID: 20345481
<table>
<tr style="background: #832F83;">
</tr>
</table>
0
 
LVL 13

Accepted Solution

by:
R7AF earned 300 total points
ID: 20345652
You can use <th> instead of <td>, and then put the following code in the head of the page. In this setup, the style will be applied to all <th> elements in all tables.
<style>
th { background: green; }
</style>

Open in new window

0
 
LVL 15

Assisted Solution

by:ncoo
ncoo earned 200 total points
ID: 20346212
Copy and paste the code below. Create as many tables as you like in the following way and all will have steelblue first rows on the page.
<html>
<head>
<style type="text/css">
thead tr th { 
background-color: steelblue;
}
</style>
</head>
<body>
<table>
<thead>
<tr><th>first row</th></tr>
</thead>
<tbody>
<tr><td>contents</td></tr>
</tbody>
</table>
</body>
</html>

Open in new window

0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question