legal or not (CSS)?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

legal or not (CSS)?

Post by Ree »

i've been searching for this for quite some time but somehow was unable to find the answer. let's say i have this in my .php:

Code: Select all

<TABLE id="admin">
   <TR>
      <TD colspan="2">
         Peter
      </TD>
   </TR>
   <TR>
      <TD id="menu">
         <?php include('menu.php'); ?>
      </TD>
      <TD id="content">
         <?php SwitchPage(); ?>
      </TD>
   </TR>
   <TR>
      <TD colspan="2">
         Peter
      </TD>
   </TR>
</TABLE>
is it legal to add this in css?

Code: Select all

table#admin td#menu
{
  stuff;
}
i tried this kind of expression with Firefox and strict doctype and it does work. however, i would like to know if it is actually legal and normal.

before you say, sure i could have done the above with divs. :) and i probably will.
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Re: legal or not (CSS)?

Post by Roja »

Ree wrote: is it legal to add this in css?
Why wouldn't it be?

You are using named (and unique!) id's, thats legal.
You are using grouped selectors together, thats legal.

What did you think wouldn't be legal?

(As a side note, I believe you need to seperate the selectors with a comma, not a space).
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

Post by Ree »

actually my question came from this.

HTML:

Code: Select all

<table id=&quote;table_id&quote;>
<tr>
	<td class=&quote;some_class&quote;>Green</td>
	<td class=&quote;some_class&quote;>Green</td>
</tr>
<tr>
	<td>Red</td>
	<td>Red</td>
</tr>
</table>

<table>
<tr>
	<td class=&quote;some_class&quote;>Blue</td>
	<td class=&quote;some_class&quote;>Blue</td>
</tr>
<tr>
	<td class=&quote;some_class&quote;>Blue</td>
	<td class=&quote;some_class&quote;>Blue</td>
</tr>
</table>
CSS:

Code: Select all

#table_id
{
  background-color: #FF0000;
}

#table_id .some_class
{
  background-color: #00FF00;
}

.some_class
{
  background-color: #0000FF;
}
as you can see in this case "#table_id .some_class" basically means that all elements that 'belong' to "#table_id" element and are of class "some_class" will have green background.

so from my previous example - "table#admin td#menu" - is this interpreted following the above logic (but since it's id, there would only be one element per id compared to multiple elements per class) - "<td> element with id "#menu" OF <table> element with id "#admin""? i do know that i could simply type "table#admin, td#menu" (with a comma) and that would be fine. but is "table#admin td#menu" interpreted the way i described, or is it simply treated as "2 separate id's separated by comma" (even if the comma is not present).

i hope you understood what i mean.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

These links will help... useful to keep open while you construct a design:

http://validator.w3.org/ ==> Checks the validity of the code compared with your DOCTYPE
http://jigsaw.w3.org/css-validator/ ==> Checks the validity of your CSS
Post Reply