PDA

View Full Version : CSS Rules



s1ntax
January 29th, 2007, 11:30 AM
Anyone know if its possible to select an element by class AND id?



<?php

$class = ( TRUE )?("showMe"):("hideMe)";
echo "<div id=\"foo\" class=\"{$class}\"> Look its a div! </div>\n";

?>


i need to access div#foo and then if div#foo has class hideMe use display:none; the showMe class is erroneous.

something like this (i know it doesnt work)


div#foo {
/* styles */
}

div#foo.hideMe {
display: none;
}



any ideas?



also, if anybody has ins with w3c i have a thought for a new CSS standard. Give rules => attributes the ability to be referenced. example (phpish syntax):



body {
margin: 0px auto;
background-color: #fff;
font-family: Arial, Helvetica, Sans-Serif,
font-size: 12px;
color: #000;
border: 1px solid #0a0;
}

div.classy {
/* would match background-colors /*
background-color: {body::this};

/* would pull border-color attribute from the body rule /*
color: {body::border-color};
}




i think making CSS more operable might be a good move? any thoughts?

aldomatic
January 29th, 2007, 12:39 PM
Anyone know if its possible to select an element by class AND id?

with javascript you can -> getElementById();

s1ntax
January 29th, 2007, 02:58 PM
read lower

aldomatic
January 29th, 2007, 04:13 PM
ahh gotcha.. :cool:

simplistik
January 29th, 2007, 07:23 PM
without a page refresh or javascript/innerhtml you can't do it. php isn't a dynamic language on it's own.

s1ntax
January 30th, 2007, 09:27 AM
im aware. i just used the PHP as an example. i have a div with two different classes depending on the state of a PHP object. i dont want javascript or anything, just css.

i want to know if theres a way to select an ID and a Class within the same rule



div#foo {
/* rules */
}

div.hideMe {
display: none;
}

<div id="foo" class="hideMe"> its a div </div>


#foo and .hideMe are the same element. is there a way to select the rule with both class and ID? something like div#foo.hideMe so i dont have to write seperate rules.

losergeekdesign
January 30th, 2007, 12:09 PM
It can be done.
div#foo{
/*rules*/
}
div#foo.hideMe {
/*rules*/
}

s1ntax
February 1st, 2007, 11:10 AM
..... i could have sworn i tried that already.


rofl. i get the snooze :z::z::z: award for that one