Welcome to WebmasterWorld Guest from 54.224.91.58

Forum Moderators: not2easy

Message Too Old, No Replies

Is it possible to link to an embedded stylesheet?

     
7:26 am on Sep 26, 2006 (gmt 0)

Junior Member

10+ Year Member

joined:May 1, 2005
posts:108
votes: 0


Let's say on one page I have embedded style information, as in:

<head>
<style type="text/css">
body {
color:red;
background-color:black;
}
</style>
</head>

and then let's say that I have another webpage that I want to also use this style information, but I don't want to write it out again... can I somehow link to, or import, the embedded style information from the first webpage?

Thanks,
Phil

7:45 am on Sept 26, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 15, 2002
posts:6807
votes: 0


Not possible.
8:02 am on Sept 26, 2006 (gmt 0)

Junior Member

10+ Year Member

joined:May 1, 2005
posts:108
votes: 0


Actually, I just figured it out, and it works. I did it like this:

<link rel='stylesheet' href='http://example.com/somepage.html' type='text/css' />

Now, to be acurate, this isn't exactly how I did it, since my site runs on php, but this is what the html output amounts to. Anyway, I'll check it later in straight html, just for my own curiousity, but this is working for me now.

9:10 am on Sept 26, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 28, 2004
posts:7999
votes: 0


You're saying that works? ODD! I will have to test that . . . but I have to ask. Why wouldn't you just put the CSS in an external file and link to it from both pages that need it?
9:26 am on Sept 26, 2006 (gmt 0)

Junior Member

10+ Year Member

joined:May 1, 2005
posts:108
votes: 0


"Why wouldn't you just put the CSS in an external file and link to it from both pages that need it?"

Kind of a long story: I have a site that allows users to create their own sub-sites within the main site. Each user has a page named "style", which contains their embedded style information, which is automatically applied to all the pages in their sub-site. Each user also has a rich-text editor, which they can use to create pages on their sub-site. So I wanted the rich-text editor to use the style from their own site, so they would see what their page would actually look like as they were creating it - and since the style information is embedded into one of their other pages, and not an external css file, I needed the rich-text editor to link to the embedded style.

It is surprizing that that works, it was such a simple solution that I almost didn't even try it.

9:40 am on Sept 26, 2006 (gmt 0)

Senior Member from ES 

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 13, 2005
posts:665
votes: 1


Did you test in other browsers?
9:47 am on Sept 26, 2006 (gmt 0)

Junior Member

10+ Year Member

joined:May 1, 2005
posts:108
votes: 0


"did you test it in other browsers?"

It's working in IE, FF and NS6. Haven't tried any others yet...

11:59 am on Sept 26, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 27, 2003
posts: 1648
votes: 2


I'd be guessing that it doesn't validate? :)
I think this is working through a bug in the browsers - because they are so tolerant of sloppy code (this is why pages that don't validate will often look fine - the browser developers have done incredibly amounts of extra work to figure out what sloppy markup means) you can put a lot of gunk in and the browsers will still extract the intended css (or in other cases html) from the file.

I wouldn't call this a technique to learn from....

5:05 pm on Sept 26, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member suzyuk is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Oct 1, 2002
posts:5199
votes: 0


my guess would be that the source shows a duplication and only the valid bits of each are being rendered?

Anyway interestingly enough I'm doing something similar to this on a site of my own (where I require embedded CSS per article, which sometimes extends to a multi page article, or gets displayed in a list along with other articles) - I did it through the CMS PHP code based on the article ID number

- in theory (and remember my PHP is not the best ;)) I created a unique variable based on the unique article number then used that variable to pull in the required CSS, via an if/else statement in the CMS code, I'm guessing this theory could be used to create a unique variable by user ID to do the same thing?

This is not really a css question (though I'm interested to see how/why your solution works) more a PHP one perhaps, your users can already store their own CSS you just need to find the cleanest way to store/retrieve the info based on your site programming

Suzy

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members