Solved

CSS setup for tables on my webpage

Posted on 2006-07-06
7
284 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
[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
  • 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
CSS: How to get responsive tables to not be so spread out on desktop 5 46
css selector 1 24
Place text over image using CSS 6 61
CSS Header Navigation Not Responsive 4 42
As a result of several questions about how to use Bootstrap I thought it would be a good idea to write down the development aspect of creating a Bootstrapped website in as little time as possible. Part 1 of this article will only concentrate on g…
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 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…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…

733 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