在网页中显示网页的最佳方式?

发布于 2024-07-26 20:06:41 字数 112 浏览 4 评论 0原文

我正在编写一个网络邮件产品,有些电子邮件的正文 CSS 会更改背景...因此,当我 Html.Decode() 该电子邮件正文时,它会更改整个页面的 CSS。

有没有好的方法来遏制这个问题?

I'm writing a webmail product and some emails have body css that changes the background ... so when I Html.Decode() that emailbody, it's altering the CSS of the entire page.

Is there a good way to contain that problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

倾其所爱 2024-08-02 20:06:41

您可以使 CSS 比电子邮件的规则更具体。 例如:

body.body.bodybody 更具体

body.body 中的任何样式与上面较小示例中的样式冲突,将覆盖。 但要阻止样式合并在一起,您需要定义每种样式。

或者,您可以重写电子邮件中的 CSS,这是当今大多数网络邮件/桌面电子邮件客户端采用的方式,无论是哪种方式。 例如,如果您为所有规则添加 #emailMessage 前缀,并将电子邮件放在

标记内,电子邮件中的所有样式仅适用于该命名空间内。

使用 iframe 来显示电子邮件只会引入更多基于可访问性等的问题。祝你好运。

You can make your CSS more specific than the email's rules. For example:

body.body is more specific than .body or body

Any styles in body.body that clash with those in the lesser examples above, will override. But to stop the styles merging together, you'll need to define every single style.

Alternatively you can go with rewriting the CSS in the emails, which is the way most webmail/desktop email clients go these days, one way or the other. If you prefix all the rules with #emailMessage, for example, and place the email inside a <div id="emailMessage"></div> tag, all the styles in the email will only apply inside that namespace.

Using an iframe to display emails only introduces more problems based around accessibility, etc etc. Good luck.

拥抱我好吗 2024-08-02 20:06:41

你的问题的答案可能是“iframe”,但在你的具体情况下,编写一个网络邮件客户端将向你介绍一个美妙的新地狱,称为“从可能极其无效的 html 生成的 html 中剥离 css”各种各样的客户对于电子邮件中应允许使用哪种 html 都有自己的想法”。

祝你好运!

The answer to your question is probably "iframe", but in your specific situation, writing a webmail client is going to introduce you to a wonderful new hell called "stripping css from possibly extremely invalid html generated by a large variety of clients that all have their own ideas about what kind of html should be allowed in an email".

Good luck!

書生途 2024-08-02 20:06:41

一种常见的方法是使用 iframe,尽管我不确定这是否适用于您的问题。

基本上它会在另一个页面中加载不同的 html 页面。 这使其成为独立的,但这确实意味着您有 2 个页面来显示一封电子邮件。

http://www.w3schools.com/TAGS/tag_iframe.asp

A common way is to use iframe, although i'm not sure this is applicable for your problem.

Basically it loads a different html page inside another page. Which makes it independent, but it does mean you have 2 pages to display one email.

http://www.w3schools.com/TAGS/tag_iframe.asp

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文