Forum Moderators: not2easy

Message Too Old, No Replies

Addressing classless/non-classed items explicitly

Can you target all span's with no class?

         

gtjuggler

10:21 pm on Dec 12, 2008 (gmt 0)

10+ Year Member



Hello All,

I have a quick general question. Lets say you have the following:


<div class="foo">
<span class="bar1">Example text 1</span>
<span>Example text 2</span>
</div>

And your css already has set styles for the many bar classes:


.bar1 {Some Style;}
.bar2 {Some Other Style;}
.bar3 {Some Other Style;}
etc...

But you want to ONLY address that non-classed span with contents "Example text 1" and do not want to have to style the span in general and then go manually reset the inherited value you just created.

Maybe a way to write span{style} that doesn't automatically propagate its style downward, or a way to write span.none or span.null ?

Thanks.

swa66

5:10 pm on Dec 13, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Attribute selector in the form of E[foo] might help indirectly with what you seek. But I've a nagging feeling IE will need some help to even understand that selector. (I'd give IE7.js a try)

[w3.org...]


span {
/* set it here */
}
span[class] {
/* undo the damage */
}
.bar1 {
/* no need to undo */
}
.bar2 {
/* no need to undo */
}

Anyway, I've not tried it, so test it well with all browsers you can get your hands on.

swa66

5:20 pm on Dec 13, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



CSS3 might end up having what it takes, but browsers won't yet be ready for this:
[w3.org...]

span:not([class]) {
/* style it here */
}

gtjuggler

5:25 pm on Dec 13, 2008 (gmt 0)

10+ Year Member



Alrighty swa. Thanks for the thorough answer :)

swa66

5:47 pm on Dec 13, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Actually, I just tested it, and the CSS3 construct is implemented in Firefox3, Safari and Opera and with IE8.js you can teach it to IE6 and IE7.

Anybody got older versions of the standards compliant browsers for testing ?


<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>untitled</title>
<style type="text/css">
.important {
color:red;
}
span:not([class]) { /* CSS3 selector */
font-weight: bold;
}
</style>
<!--[if lt IE 8]>
<script src="http://ie7-js.googlecode.com/svn/version/2.0(beta3)/IE8.js"
type="text/javascript"></script>
<![endif]-->
</head>
<body>
<p>
<span class="important">Am I red, but not bold</span>
<span>Am I bold</span>
</p>
</body>
</html>

The CSS validator will stumble over it though.

gtjuggler

5:52 pm on Dec 13, 2008 (gmt 0)

10+ Year Member



The unmentioned details is this is all generated from DITA with xslt and then from the HTML it gets compiled into a .chm for documentation for a product... So I'll test it but I'm assuming the chm will die on that part.

I do, however, really appreciate all of the research! I'll most definitely need to use that one day. :P