/    Sign up×
Community /Pin to ProfileBookmark

CSS not working in RSS Feed

I can’t get CSS to work in an RSS Feed. I’ve followed multiple examples that I’ve found online with no success. Is there something I’m missing?

XML Code:

[CODE]
<?xml version=”1.0″ encoding=”ISO-8859-1″?>
<?xml-stylesheet type=”text/css” href=”/Stylesheets/RSSFeed.css”?>
<rss version=”2.0″>
<channel>
<title>Company Name</title>
<copyright>Copyright 2008</copyright>
<link>http://www.domain.com</link>
<image>
<url>http://www.domain.com/Images/Logo.gif</url>
<title>Company Name</title>
<link>http://www.domain.com</link>
</image>
<description>Company’s RSS Feed</description>
<category>Manufacturing</category>
<category>IT/Internet/Web Development</category>
<managingEditor>[email protected] (Webmaster</managingEditor>
<webMaster>[email protected] (Webmaster)</webMaster>
<ttl>15</ttl>
<lastBuildDate>Tue, 19 Aug 2008 15:00:00 -0400</lastBuildDate>
<pubDate>Tue, 19 Aug 2008 15:00:00 -0400</pubDate>
<item>
<title>First Entry</title>
<author>[email protected] (Webmaster)</author>
<guid isPermaLink=”false”>10000001</guid>
<pubDate>Mon, 18 Aug 2008 11:28:41 -0400</pubDate>
<category>Web Development</category>
<category>Website Updates</category>
<link>http://www.domain.com</link>
<description><![CDATA[Our first rss feed entry]]></description>
</item>
</channel>
</rss>
[/CODE]

CSS Code:

[CODE]
channel link, channel language, channel copyright, channel managingEditor, channel webMaster, channel docs, channel lastBuildDate {
display:none;
}
rss {
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:0.7em;
line-height:130%;
margin:1em;
}
/* HEADER */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
channel title {
display:block;
padding:0.4em 0.2em;
color:#FFF;
border-bottom:1px solid black;
font-weight:bold;
font-size:140%;
background-color:#4483C7;
}
channel description {
display:block;
float:left;
font-size:130%;
font-weight:bold;
margin:0.5em;
}
/* CONTENT */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
channel item {
background-color:#FFFFEE;
border:1px solid #538620;
clear:both;
display:block;
padding:0 0 0.5em;
margin:1em;
}
channel item title {
background-color:#538620;
border-bottom-width:0;
color:#FFF;
display:block;
font-size:110%;
font-weight:bold;
margin:0;
padding:0.3em 0.5em;
}
channel item description {
display: block;
float:none;
margin:0;
text-align: left;
padding:0.2em 0.5em 0.4em;
color: black;
font-size:100%;
font-weight:normal;
}
channel item link {
color:#666;
display:block;
font-size:86%;
padding:0 0.5em;
}
channel item pubDate {
color:#666;
display:block;
font-size:86%;
padding:0 0.5em;
}
[/CODE]

to post a comment

8 Comments(s)

Copy linkTweet thisAlerts:
@Mr__E__CrypticAug 21.2008 — I've never actually used CSS for RSS, but I imaging the css should be more in the vein of:

[code=html]channel > title {
}

item{
}

item > title{
}

item > description{
}
etc etc.[/code]
Copy linkTweet thisAlerts:
@nbcrockettauthorAug 21.2008 — I've never seen that used in CSS, but I tried it anyway and it still didn't work. Any other ideas?

Thanks
Copy linkTweet thisAlerts:
@Kostas_ZotosAug 23.2008 — Hi,

Everything seems OK to me.. except of a slash in the path of CSS file..

(the "problematic" slash shown in red)

[CODE]<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/css" href="[COLOR="Red"]/[/COLOR]Stylesheets/RSSFeed.css"?>[/CODE]


Use: [B]href="Stylesheets/RSSFeed.css"[/B] [COLOR="Green"] [B](NO initial slash / on the path)[/B][/COLOR]

Cheers!

Kostas
Copy linkTweet thisAlerts:
@nbcrockettauthorAug 25.2008 — In this case the slash does belong there. The slash designates that it starts at the root of the domain. In other words the stylesheets folder is directly in the root folder of the website (i.e. www.domain.com/Stylesheets/RSSFeed.css). No slash designates that the stylesheets folder is in the same folder as my xml file, which is not the case (i.e. www.domain.com/Pages/Stylesheets/RSSFeed.css). I tested it anyway just in case I was wrong.
Copy linkTweet thisAlerts:
@Kostas_ZotosAug 25.2008 — Hi,

Ok I see ?

You use relative path, but the "Stylesheets" folder is not a subfolder where your .XML file resides..

The syntax in this case requires something like this:

[CODE]<?xml-stylesheet type="text/css" href="../Stylesheets/RSSFeed.css"?>[/CODE]
(If the folder with your .xml is in a subfolder under the site root)

OR:
[CODE]<?xml-stylesheet type="text/css" href="../../Stylesheets/RSSFeed.css"?>[/CODE]
(If the folder with your .xml is in a subfolder 2 levels under the site root)

etc..

The [B]../[/B] denotes one level (folder) up (back) form your current location.


----------------------------
As alternative may use the absolute path:
[CODE]<?xml-stylesheet type="text/css" href="http://www.domain.com/Stylesheets/RSSFeed.css"?>[/CODE]

Regards!

Kostas
Copy linkTweet thisAlerts:
@nbcrockettauthorAug 25.2008 — Thanks for your help Kostas and Cryptic, but it turns out that there was absolutely nothing wrong with my CSS. Turns out IE7 and FF2 don't display CSS. I came across this by accident when I went to an IE6 machine and all of the CSS appeared.

Two more questions though. First question, is it possible to show CSS in IE7 and FF2. Second question, IE6 doesn't show my html tags as html. Instead it just displays it as text. Is there a way to use html in IE6.
Copy linkTweet thisAlerts:
@Kostas_ZotosAug 26.2008 — Hi,

I am not using IE7 or FF2, so I can't suggest something usefull. Although normally it must be a way to display CSS formating XML in these browsers..

Regarding the second question: The html tags are treated as any other xml tag and you need to style your xml for example using XSLT or parse the XML inside a HTML document with JavaScript and also using (that you already did) CSS.

The better way is by using the XSLT, this allows you to convert-output your xml to other formats like html, xhtml, reformatting xml, etc..

Look for info of how to use .xsl files (are a lot of powerfull and versatile than CSS)

Regards!

Kostas
Copy linkTweet thisAlerts:
@Kostas_ZotosAug 27.2008 — If you are the author or can edit the xml (rss) file, you can mix html and xml tags using appropriate namespaces.. In this way the html tags identified and render as html..

This works with no problems in the Opera, Netscape and FireFox (1.0) I've tested, however at least in IE 6 seems that most html tags not identified (IE 6 not fully conforms with the standards, eg. XML DOM, etc..)

The modified file (for demonstration) is like this:
[CODE]<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/css" href="/Stylesheets/RSSFeed.css"?>
<rss version="2.0" [COLOR="Red"]xmlns:htm="http://www.w3.org/1999/xhtml"[/COLOR]> [COLOR="Green"]<!-- Define the namespace for our "htm" prefix -->[/COLOR]
<channel>
<title>Company Name</title>
<copyright>Copyright 2008</copyright>
<link>http://www.domain.com</link>
<image>
<url>http://www.domain.com/Images/Logo.gif</url>
<title>Company Name</title>
<link>http://www.domain.com</link>
</image>
[COLOR="Green"]<!-- Use a html element (with a default namespace) in order to insert a html section -->[/COLOR]
[COLOR="Red"]<html xmlns="http://www.w3.org/1999/xhtml">
<br/><br/>
<div style="width:640px;height:30px;color:#00aaaa;font:bold 14pt Tahoma;padding:10px;border:1px solid">
div Test

</div><br/>

</html>[/COLOR]
[COLOR="Green"]<!-- Use a span tag to Change the color -->[/COLOR]
<description>[COLOR="Red"]<htm:span style="color:#ff5500">Company's RSS Feed</htm:span>[/COLOR]</description>
<category>Manufacturing</category>
<category>IT/Internet/Web Development</category>
<managingEditor>[email protected] (Webmaster</managingEditor>
<webMaster>[email protected] (Webmaster)</webMaster>
<ttl>15</ttl>
<lastBuildDate>Tue, 19 Aug 2008 15:00:00 -0400</lastBuildDate>
<pubDate>Tue, 19 Aug 2008 15:00:00 -0400</pubDate>
<item>
<title>First Entry</title>
<author>[email protected] (Webmaster)</author>
<guid isPermaLink="false">10000001</guid>
<pubDate>Mon, 18 Aug 2008 11:28:41 -0400</pubDate>
<category>Web Development</category>
<category>Website Updates</category>
[COLOR="Green"]<!-- Use the html tag (with our custom prefix) to define a html link -->[/COLOR]
<link>[COLOR="Red"]<htm:a href="http://www.domain.com">http://www.domain.com</htm:a>[/COLOR]</link>
<description><![CDATA[Our first rss feed entry]]></description>
</item>
[COLOR="Green"]<!-- Use a html element (with a default namespace) in order to insert a xhtml section -->[/COLOR]
[COLOR="Red"]<html xmlns="http://www.w3.org/1999/xhtml">
<body style="background:#ffffee; padding:10px;border:1px solid">
<b> Test HTML </b><br/>
<i> OK </i><br/>
<a href="http://www.mydomain.com" title="Click to visit the site">Click here</a>
<br/><br/>
<span style="color:#ff2222">Span Test</span>
</body>
</html>[/COLOR]
</channel>
</rss>[/CODE]


The above uses the default namespace for the xhtml (and a custom prefix "htm" to insert mixed xhtml tags) in order to separate the html elements from our -custom- xml tags.

Example here:
[CODE]<[B]htm:span[/B] style="color:#ff5500">Company's RSS Feed</[B]htm:span[/B]>[/CODE]
The "[B]htm[/B]" is our custom prefix (whose namespace has been defined in the root element as show in the next line)
[CODE]<rss version="2.0" [B]xmlns:htm="http://www.w3.org/1999/xhtml"[/B]> <!-- Define the namespace for our "htm" prefix -->[/CODE]
"[B]htm:span[/B]" is the element's name (qualified name) and this makes that element a xhtml element (so separated from the rest xml tags)

A browser that is aware of the concept of namespaces normally will render these tags as html - xhtml..

These even not required any external CSS or other style file, just plain mixture of custom (xml) and html standard tags.. However an important point that need to be examined, is the degree of support of the various browsers' versions..

Cheers!

Kostas
×

Success!

Help @nbcrockett 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 6.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ,
analytics: Fullres
});

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: @Marika,
tipped: article
amount: 1000 SATS,

tipper: @hatem774,
tipped: article
amount: 1 SATS,

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