Solved

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

Posted on 2007-11-25
3
795 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

707 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