如何将我的 CSS 样式表应用到 RSS 提要

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/118685/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 19:58:02  来源:igfitidea点击:

How can I apply my CSS stylesheet to an RSS feed

cssrssblogs

提问by Kip

On my blog I use some CSS classes which are defined in my stylesheet, but in RSS readers those styles don't show up. I had been searching for class="whatever"and replacing with style="something: something;". But this means whenever I modify my CSS I need to modify my RSS-generating code too, and it doesn't work for a tag which belongs to multiple classes (i.e. class="snapshot accent"). Is there any way to point to my stylesheet from my feed?

在我的博客上,我使用了一些在我的样式表中定义的 CSS 类,但是在 RSS 阅读器中这些样式不会显示出来。我一直在寻找class="whatever"并替换为style="something: something;". 但这意味着每当我修改 CSS 时,我也需要修改我的 RSS 生成代码,并且它不适用于属于多个类(即class="snapshot accent")的标签。有什么办法可以从我的提要中指向我的样式表吗?

回答by Joel Spolsky

The popular RSS readers WILL NOT bother downloading a style sheet, even if you provide one and link to it using <?xml-stylesheet?>.

流行的 RSS 阅读器不会费心下载样式表,即使您提供一个样式表并使用<?xml-stylesheet?>.

Many RSS readers simply strip all inline styleattributes from your tags. From testing today, I discovered that Outlook 2007 seems to strip out all styles, for example, even if they are inline.

许多 RSS 阅读器只是style从您的标签中删除所有内联属性。从今天的测试中,我发现 Outlook 2007 似乎删除了所有样式,例如,即使它们是内联的。

Good RSS readers allow a limited set of inline styleattributes. See, for example, this article at Bloglinesabout what CSS they won't strip. From experimentation, Google Reader seems to pass through certain styles unharmed.

好的 RSS 阅读器允许有限的内联style属性集。例如,请参阅Bloglines 上的这篇关于他们不会删除哪些 CSS 的文章。从实验来看,Google Reader 似乎可以安然无恙地通过某些样式。

The philosophy of RSS is indeed that the reader is responsible for presentation. Many people think that RSS should be plain text and that CSS in RSS feeds is inappropriate. It's probably not appropriate to impose a different font on your RSS feeds. However, certain types of content (for example, images floated on the left, with captions positioned carefully) require a minimal amount of styling in order to maintain their semantic meaning.

RSS 的理念确实是读者负责呈现。许多人认为 RSS 应该是纯文本,而 RSS 提要中的 CSS 是不合适的。在您的 RSS 提要上强加不同的字体可能是不合适的。但是,某些类型的内容(例如,浮动在左侧的图像,带有仔细定位的标题)需要最少的样式以保持其语义含义。

回答by Geoff

The point of RSS is to be display agnostic. You should not be putting style attributes on your feed.

RSS 的要点是与显示无关。你不应该在你的提要上放置样式属性。

回答by Brian Matthews

I found this blog postthat describes how to add style to your RSS feed.

我发现这篇博客文章描述了如何向 RSS 提要添加样式。

回答by Ryan Cerniglia

Because RSS is (supposed to be) XML, you can use XML stylesheets.

因为 RSS 是(应该是)XML,所以您可以使用 XML 样式表。

http://www.w3.org/TR/xml-stylesheet/

http://www.w3.org/TR/xml-stylesheet/

回答by Bryan M.

The purpose of an RSS feed is to allow the easy transmission of content to places outside your site. The whole idea is that the content within the feed is format-free, so that it can be read by any piece of software. The program that is reading the your feed is in charge of how to present it visually. For example, if you had a website that read RSS, you would want to parse the feed into HTML, and style it that way. However, if you were building a desktop application to read the feed, you would implement the formatting quite differently.

RSS 提要的目的是允许将内容轻松传输到站点之外的地方。整个想法是提要中的内容是无格式的,因此可以被任何软件读取。正在阅读您的提要的程序负责如何以视觉方式呈现它。例如,如果您有一个读取 RSS 的网站,您可能希望将提要解析为 HTML,并以这种方式设置样式。但是,如果您正在构建一个桌面应用程序来读取提要,那么您将完全不同地实现格式设置。