/    Sign up×
Community /Pin to ProfileBookmark

Accessing external CSS from the body?

Is there any way to access an external CSS from the body? Or, change the CSS for the entire document just using things within the body tag? I think there may be a JavaScript solution; I also asked in the JavaScript forum.

to post a comment
CSS

8 Comments(s)

Copy linkTweet thisAlerts:
@JayMApr 10.2005 — Hmm... I'm not sure I totally understand. Forgive me for asking, but why would you want an external CSS file in the body anyway? Inserting CSS into your <head> would affect your entire document, and trying to insert it into your <body> would be pointless.
Copy linkTweet thisAlerts:
@FangApr 10.2005 — You can [URL=http://www.alistapart.com/articles/bodyswitchers/]swap style sheets[/URL], change rules, selectors or values. What do you want to do?
Copy linkTweet thisAlerts:
@ray326Apr 11.2005 — I think all references to external style sheets have to be done in the head.
Copy linkTweet thisAlerts:
@mokuauthorApr 11.2005 — Uh, thanks Fang. That helped a lot! ?
Copy linkTweet thisAlerts:
@mikepurvisApr 11.2005 — Forgive me for asking, but why would you want an external CSS file in the body anyway?[/QUOTE]

Forgive me for answering, but I can think of several reasons, the most obvious of which being if you wanted styles localized to a small section of a document. For example, external content such as advertising or a feed.

It would be tremendously useful to be able to insert a <style> block and have the styles be active only until the current scope ends.

These objectives can be accomplished by 'phoning ahead' to find out what the ad-styles are, but most archaic CMSes weren't built with that in mind.
Copy linkTweet thisAlerts:
@JayMApr 11.2005 — 
It would be tremendously useful to be able to insert a <style> block and have the styles be active only until the current scope ends.
[/QUOTE]


I suppose, but can't that be done using <div></div>?
Copy linkTweet thisAlerts:
@ray326Apr 12.2005 — I suppose, but can't that be done using <div></div>?[/QUOTE]
Only inline. He'd like to do an external at that point.
Copy linkTweet thisAlerts:
@WoDApr 12.2005 — If you want to style a specific part of a page differently then you would simply encompass it in a DIV, and then include the styles for that section in the external (or inline, if you prefer) stylesheet using CSS selectors to apply the style only to the content of that DIV.

Of course, this has nothing to do with changing styles on the fly, which is what moku was asking.

To do this, I would typically create several classes with the different styles and switch them with javascript using object.className. I produced my fading DHTML menu this way because I was not sure how to adjust CSS opacity via the DOM.
×

Success!

Help @moku spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...