admin管理员组文章数量:1221766
I'm trying to embed a preformatted scientific paper into my website, without interference from my website's theme. The article is comprised of HTML and CSS content generated from a LaTeX manuscript, which I want to render exactly as-is. My website's theme ends up styling parts of that article's HTML content, which I'm trying to avoid. For example, the theme's stylesheet has rules for link formatting that are more specific than those specified by the article.scss
, so they take precedence.
This is just a simple GitHub Pages site that's statically generated by Jekyll, but this question is more general than that. I'm using a a third party theme that styles just about everything and works really well on most pages, where I just provide dumb MarkDown content for it to style and present.
On this article's page, I want to use the common site header (so I need the theme.scss
, I can't just skip it for that page), but the rest of the page content should just be the article's HTML as-is, with its own article.scss
for styling it.
What's the best way to embed this article's HTML and CSS on a "clean slate"?
One approach to fix this was to find all the offending theme rules, and add new more-specific rules like .article p { font-size: unset; }
, etc. This was annoying but worked decently well on my first go at this, but unfortunately, it totally breaks when I change the theme: some of those "reset rules" become obsolete, and other new ones need to be made for the new theme's quirks.
An iframe
came to mind, but that gave me a "you're doing it wrong" feeling. Is there a native CSS way to say something like "this tag and its children belong to their new isolated context, with their own set of styles"?
I'm trying to embed a preformatted scientific paper into my website, without interference from my website's theme. The article is comprised of HTML and CSS content generated from a LaTeX manuscript, which I want to render exactly as-is. My website's theme ends up styling parts of that article's HTML content, which I'm trying to avoid. For example, the theme's stylesheet has rules for link formatting that are more specific than those specified by the article.scss
, so they take precedence.
This is just a simple GitHub Pages site that's statically generated by Jekyll, but this question is more general than that. I'm using a a third party theme that styles just about everything and works really well on most pages, where I just provide dumb MarkDown content for it to style and present.
On this article's page, I want to use the common site header (so I need the theme.scss
, I can't just skip it for that page), but the rest of the page content should just be the article's HTML as-is, with its own article.scss
for styling it.
What's the best way to embed this article's HTML and CSS on a "clean slate"?
One approach to fix this was to find all the offending theme rules, and add new more-specific rules like .article p { font-size: unset; }
, etc. This was annoying but worked decently well on my first go at this, but unfortunately, it totally breaks when I change the theme: some of those "reset rules" become obsolete, and other new ones need to be made for the new theme's quirks.
An iframe
came to mind, but that gave me a "you're doing it wrong" feeling. Is there a native CSS way to say something like "this tag and its children belong to their new isolated context, with their own set of styles"?
1 Answer
Reset to default 1I believe the most appropriate approach is to use the Shadow DOM, which can be done from pure HTML like so:
p { color: red; }
<p>Text red</p>
<div>
<template shadowrootmode="open">
<style>p {text-decoration: underline}</style>
<p>Text in shadow DOM and not affected by red</p>
</template>
</div>
Alternatively, you can also use JS to dynamically load content in your Shadow DOM.
I hope that can help you.
本文标签: How can I embed prestyled HTML with being effected by the surrounding CSSStack Overflow
版权声明:本文标题:How can I embed prestyled HTML with being effected by the surrounding CSS? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739301392a2157157.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
margin-left
on list items, so it ends up as whatever the browser defaults to. My previous theme didn't set it, so it kept that15px
browser default and looked okay. Turns out my new theme does definemargin-left: 30px
, which is now more indented than intended. – Alexander Commented Feb 7 at 18:19