Div与外部样式表? [英] Div with external stylesheet?
问题描述
我已经给了一个外部样式表(.css文件),不能以任何方式改变。但是,我需要将此样式表应用于单个div,因此在我已经存在的网页中的div的内容。我目前正在将样式表的内容作为文本读入一个空白样式标签(使用.innerHTML)在div中,我需要影响,但这仍然影响整个网页,而不仅仅是单个div。
I have been given an external stylesheet (.css file) that may not altered in any way whatsoever. However I need to apply this stylesheet to a single div and therefore the contents of the div in my already existing webpage. I am currently reading the contents of the stylesheet as text into a blank style tag (using .innerHTML) within the div I need to affect but this still affects the entire web page rather than just the single div. Could someone please help with this?
推荐答案
IFRAME解决方案的工作原理如下:
The IFRAME solution works like this:
在您的主HTML文件中,您将拥有您的DIV:
In your main HTML file, you'll have your DIV:
<div id="myspecialdiv">
<iframe width="100%" height="100%" frameborder="0" src="divcontent.html"></iframe>
</div>
根据需要设计样式。 divcontent.html文件应该是一个完整的HTML文件,包括DIV标记的内容和使用您的外部样式表的LINK:
Style that as you need it. The divcontent.html file should be a complete HTML file, including the content of the DIV tag, and a LINK using your external stylesheet:
<html>
<head>
<link rel="stylesheet" href="path/to/external/stylesheet.css" />
</head>
<body>
<!-- The contents of your DIV -->
</body>
</html>
这篇关于Div与外部样式表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!