CSS-hack - 在网站的正文中添加css [英] CSS-hack - Adding css in the body of a website
本文介绍了CSS-hack - 在网站的正文中添加css的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我被困在一个情况,我只能访问的网站的身体,而不是头部。我必须使用一个新的样式表。现在的解决方案,我遇到了添加CSS文件在网站的正文。当然,这是一个黑客,所以我想知道是否有一个更好的解决方案呢?
I am stuck in a situation where I only have access to the body of the website and not the head. I have to use a new stylesheet. Now the solution that I came across to add the CSS file in the body of the website. Of course, it is a hack so I was wondering if there is a better solution to it?
推荐答案
页面上的外部CSS文件是:
The conventional way to load external CSS files on a page is:
<head>
<link rel="stylesheet" type="text/css" href="file.css" />
</head>
使用基本的JavaScript来做,你创建一个Javascript函数:
Using basic javascript to do it, you shoud create a Javascript function:
<script type="text/javascript">
function loadCSS(filename){
var file = document.createElement("link");
file.setAttribute("rel", "stylesheet");
file.setAttribute("type", "text/css");
file.setAttribute("href", filename);
document.head.appendChild(file);
}
//just call a function to load a new CSS:
loadCSS("path_to_css/file.css");
</script>
这篇关于CSS-hack - 在网站的正文中添加css的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文