Solved

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

Posted on 2007-11-25
3
782 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 75 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 50 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
This article discusses four methods for overlaying images in a container on a web page
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

831 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