Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

CSS Forum


You are currently viewing our CSS Forum as a guest. Please register to participate.
Login



Reply
Select all but * CSS selector
Old 07-01-2007, 07:06 PM Select all but * CSS selector
Moldarin's Avatar
Extreme Talker

Latest Blog Post:
Keyword Density and Title Tags
Posts: 201
Trades: 0
Hi,

How to select all but one element with CSS selectors?

Code:
body { display: none; }
body .article { display: block; }
The above does not work as the body already is hidden. I want all elements decendent from .article to show (not nesescarily as block, though) and all elements outside .article hidden.
__________________
I do not share ad revenue.
Moldarin is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-01-2007, 08:48 PM Re: Select all but * CSS selector
Experienced Talker

Posts: 30
Name: Ben Henick
Trades: 0
To answer your question, there is no such thing as an "everything-but-x" selector that's broadly supported. The closest you're going to get is

* { attribute: value; etc.; }
#exception { attribute: reset_value; etc.; }

CSS3 does support *:not(#exception) { attribute: value; } which does exactly the same thing as the preceding two rules combined, but I've never seen it in the wild.

Whoa. Before I (or anyone else) can hope to help you, you should probably explain why you're attempting to clobber the layout properties of the entire browser canvas (which would be the expected practical consequence of specifying body { display: none; }), assuming such an attr-val pair would be rendered... and in nine years of using CSS, I've never run across a situation in which I found that to be a necessary step. This assumes, of course, that you haven't already (see below).

(Yes, nine years. Grab my RL name from my profile and Google it.)

If you simply want .article to display while stashing everything else away (as might be the case if you're putting together a print stylesheet), then leave body untouched, and do the following:

body * { display: none; }
.article { display: block; margin: as_necessary; }

In point of fact, you should either have one article per document, or (if that's not possible) a container called #articleset (or whatever; I'd use #bodyCopy myself) that would contain nothing but elements that have been assigned to the class article. Doing so will increase the specificity of the selector you use to enforce the presentation requirement you described. Classes are more specific than single elements by one order of magnitude; ID's are more specific by two orders of magnitude. The unversal selector has no discrete specificity assigned, but overrules the browser's stylesheet.

Last edited by persist1; 07-01-2007 at 08:54 PM.. Reason: Wanted to explain the unviersal selector.
persist1 is offline
Reply With Quote
View Public Profile
 
Old 07-02-2007, 03:29 AM Re: Select all but * CSS selector
Moldarin's Avatar
Extreme Talker

Latest Blog Post:
Keyword Density and Title Tags
Posts: 201
Trades: 0
The problem with usnig body * is that all elements inherit that value. Then I have to set each and every possible element with either inline and block.

Have you ever tried *:not(.something) {bla-bla}? Does it work in any popular browser:not(IE)?
__________________
I do not share ad revenue.
Moldarin is offline
Reply With Quote
View Public Profile
 
Old 07-02-2007, 10:14 AM Re: Select all but * CSS selector
Mooofasa's Avatar
Defies a Status

Posts: 1,611
Name: Michael (mik) Land
Location: England
Trades: 0
Persist's method is the only one that will work. CSS3 is still not released, so that's a no-go for at least a while.

Remember that using display: none literally rips that element out of the page structure and it will have no effect on other elements (other than those that cascade from it). Using visibility: hidden, might be a better choice.

I'd also like to know why are you doing this?

Last edited by Mooofasa; 07-02-2007 at 10:25 AM..
Mooofasa is offline
Reply With Quote
View Public Profile Visit Mooofasa's homepage!
 
Reply     « Reply to Select all but * CSS selector
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.03559 seconds with 12 queries