 |
CSS Cascading Style Sheets All issues relating to Cascading Style Sheets (CSS). |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the CSS Cascading Style Sheets section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

February 23rd, 2006, 04:56 PM
|
Authorized User
|
|
Join Date: Oct 2004
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Change border color for every cell of a table
Hi all,
I want to change the border color of every cells or rows of a table but I am not quite sure what is the best way to do it. Personally, I want to change on the table level, not on cells or rows object.
Setting border=1 on table tag will turn all border on but when we try to change border color then only 4 sides border are changed and inside are not. Does anybody know how to do this?
JDang
|

February 23rd, 2006, 05:02 PM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 425
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
CSS handles borders os TABLE and TD (and TH) separately.
For all tables.
table,td,th { border: 2px solid #f00 }
If you want to affect just one table, you have to use a more specific selector (for instance by giving the table an id or class).
http://www.w3.org/TR/REC-CSS2/tables.html
--
http://yupapa.com
|

February 23rd, 2006, 05:03 PM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 425
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
Hee-hee! You got me this time, Richard. :D
--
http://yupapa.com
|

April 4th, 2010, 06:12 PM
|
Registered User
|
|
Join Date: Apr 2010
Posts: 70
Thanks: 4
Thanked 0 Times in 0 Posts
|
|
Is there a way to change the border color of each row?
|

April 4th, 2010, 06:21 PM
|
Friend of Wrox
|
|
Join Date: Dec 2008
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
|
|
Give them different CSS classes.
|

April 4th, 2010, 06:26 PM
|
Registered User
|
|
Join Date: Apr 2010
Posts: 70
Thanks: 4
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by PeterPeiGuo
Give them different CSS classes.
|
That's what I figured, but it didn't work. Is the code like this?
Code:
<tr class="example">
<td>Hi </td>
<td>Hello </td>
</tr>
<tr class="test">
<td>Test </td>
<td> Testing </td>
</tr>
And the style sheet looks like this?
Code:
tr.example {
border-color:red;
All other border stuff in here;}
tr.test {
border-color:gray;
All other border stuff in here;}
|

April 4th, 2010, 06:49 PM
|
Friend of Wrox
|
|
Join Date: Dec 2008
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
|
|
For example:
Code:
<html>
<head>
<style>
<html>
<head>
<style>
table {
border-style:solid;
border-width:1px;
border-color: yellow;
}
tr.example td {
border-style:solid;
border-color:red;
border-width: 1px;
padding: 10px;
}
tr.test td {
border-style:solid;
border-color:green;
border-width: 1px;
padding: 10px;
}
</style>
</head>
<body>
<table>
<tr class="example">
<td>Hi </td>
<td>Hello </td>
</tr>
<tr class="test">
<td>Test </td>
<td> Testing </td>
</tr>
</table>
</body>
</html>
|

April 7th, 2010, 09:23 AM
|
Registered User
|
|
Join Date: Apr 2010
Posts: 70
Thanks: 4
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by PeterPeiGuo
For example:
Code:
<html>
<head>
<style>
<html>
<head>
<style>
table {
border-style:solid;
border-width:1px;
border-color: yellow;
}
tr.example td {
border-style:solid;
border-color:red;
border-width: 1px;
padding: 10px;
}
tr.test td {
border-style:solid;
border-color:green;
border-width: 1px;
padding: 10px;
}
</style>
</head>
<body>
<table>
<tr class="example">
<td>Hi </td>
<td>Hello </td>
</tr>
<tr class="test">
<td>Test </td>
<td> Testing </td>
</tr>
</table>
</body>
</html>
|
could it be that my browswer doesn't support that when using <tr>?
I think it said in the book that some browsers can't support <tr>, so instead you should use <td>, but I tried that also, and it didn't work.
And I even tried it in one of the W3Schools.com "Try it out yourself" activities, and it worked.
|

April 7th, 2010, 10:15 AM
|
Friend of Wrox
|
|
Join Date: Dec 2008
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
|
|
Actually in my example, the style is applied on td, not tr. tr is there merely as a selector to narrow down to a particular group of td's.
I just tested my last example as is with IE8, Opera, Firefox, Safari and Chrome, all with the latest version on Windows, and they all worked.
Last edited by PeterPeiGuo; April 7th, 2010 at 10:33 AM..
|
|
 |