Solved

CSS setup for tables on my webpage

Posted on 2006-07-06
7
279 Views
Last Modified: 2013-12-16
<table border="0" bgcolor="#ffffff" cellpadding="2" cellspacing="3" width="100%">
<tr>
         <td bgcolor="#cccccc">Section Heading</td>
</tr>
<tr>
         <td align="left">Section Sub Heading</td>
</tr>
<tr>
        <td>
         <table border="0" width="100%" cellspacing="0" cellpadding="0">
         <tr>
                  <td><a href="">title</a><a href=""><img src=""></a></td>
                  <td>description</td>
         </tr>
         </table>
         </td>
</tr>
</table>

--------------------------------

So what I want to do is be able to modify the following elements of the above HTML using CSS.

1.  The background color of the main table
2.  change the background color of the row that has the 'Section Heading'
3.  change the background color of the row that has the 'Section Sub Heading'
4.  change the background color of the inner table

What is the best way to go about this?  Should I use ID's or div's?

Please provide sample CSS that modifies each of the elements.



0
Comment
Question by:EENoob
  • 4
  • 3
7 Comments
 
LVL 10

Expert Comment

by:jagadeesh_motamarri
ID: 17053320
Well....if your data is a tabular data then don't prefer using CSS.

The intension of using CSS should be somthing like - converting tables using divs.

....But still if you need to conver this table accroding to your specs.....here it is

CODE:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>

<style media="all" type="text/css">

#table{

position:relative;

}

#first{
background-color:#00CCCC;

}

#second{

background-color:#99CC66;


}

#third_1{
width:50%;
float:left;
}

#third_2{
width:50%;
position:relative;

}

</style>
 
</head>

<body>
<table border="0" bgcolor="#ffffff" cellpadding="2" cellspacing="3" width="100%">
<tr>
         <td bgcolor="#cccccc">Section Heading</td>
</tr>
<tr>
         <td align="left">Section Sub Heading</td>
</tr>
<tr>
        <td>
         <table border="0" width="100%" cellspacing="0" cellpadding="0">
         <tr>
                  <td><a href="">title</a><a href=""><img src=""></a></td>
                  <td>description</td>
         </tr>
         </table>
    </td>
</tr>
</table>



 

<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>

<div id="table">
<div id="first">
Section headin
</div>

<div id="second">
Section sub heading
</div>


<div id="third_1">
<a href="">title</a><a href=""><img src=""></a>
</div>


<div id="third_2">
  <p>Description</p>
  </div>

</div>

</body>
</html>


............i've included your code and mine. That will help you to make a difference.

Lemme know if you need to know more abut the css i've used.


____Jags.
0
 

Author Comment

by:EENoob
ID: 17053529
Hi,

Instead of using div's, can I just add an ID to the table?
<table border="0" ID="table1">


then in CSS

table#table1
{
   backgroundcolor: #fffff;
}


>>if your data is a tabular data then don't prefer using CSS.
I'm not sure how correct that statement is.

anyhow, I'm having a hard time being able to reference the 2nd and 3rd <tr>'s......I don't want to make a global change to all the <tr> in my outer table since the 2nd and 3rd row's may have different background colors.
0
 
LVL 10

Expert Comment

by:jagadeesh_motamarri
ID: 17053633
...well I personally don't prefer placing tabular data in division. And even many experts suggest the same. (If the data is many rows and rows.)

The W3C defines class ID as "a unique identifier to an element". if your intention is just to change the backgound color you can directly do that using bgcolor attribute. But if your intention is using stylesheets...u can do it either by class or id. Your above example is for id. You can apply the same property to more than one element (say table) using the class.

URL: http://www.tizag.com/cssT/cssid.php


>>I'm having a hard time being able to reference the 2nd and 3rd <tr>'s......I don't want to make a global change to all the <tr> in my outer table since the 2nd and 3rd row's may have different background colors.

you don't want to make global change to your tr...you can define various styles and use ID to refer them in your tr tags.

Let me know if you need more explanation?

_____Jags.



0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:EENoob
ID: 17053682
Can you give me a sample CSS in the way I want it using ID's or even classes that changes the background color of the outer table, and change the color of the 2nd and 3rd rows each having a different color, and change the background color of the inner table.

that's the solution i'm looking for! thanks!
0
 
LVL 10

Accepted Solution

by:
jagadeesh_motamarri earned 150 total points
ID: 17053827
check out this -

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>

<style media="all" type="text/css">

#table{

position:relative;

}

#first{
background-color:#00CCCC;

}

#second{
background-color:#99CC66;
}

#third{
background-color:#0099CC;}


</style>
 
</head>

<body>
<table border="0" cellpadding="2" cellspacing="3" width="100%">
<tr>
         <td id="first">Section Heading</td>
</tr>
<tr>
         <td id="second">Section Sub Heading</td>
</tr>
<tr>
        <td>
         <table border="0" width="100%" cellspacing="0" cellpadding="0">
         <tr id="third">
                  <td><a href="">title</a><a href=""><img src=""></a></td>
                  <td>description</td>
         </tr>
         </table>
    </td>
</tr>
</table>




</body>
</html>


...let me know changes according to this. Did u get a chance to know the difference between using ID and Class in the tags.

____Jags.
0
 

Author Comment

by:EENoob
ID: 17054071
from what I understood, class are good for implementing a style to many elements at the same time.

ID is good for applying a style to a single element?
0
 
LVL 10

Expert Comment

by:jagadeesh_motamarri
ID: 17054092
:-)

Can i know the reason for B Grade.


Thank You,
_____Jags.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

When writing CSS, there are a few simple rules that will make your life easier.    1. Using ‘* {box-sizing:border-box;}’. Using this will wrap all your elements in a nice little compact box-model that will give you the width you want, like so... …
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.
The purpose of this video is to demonstrate how to automatically show related posts at the bottom of a blog post in WordPress. This will be demonstrated using a Windows 8 PC. Plugin “Yet Another Related Posts Plugin” will be used. Go to your…
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now