我使用CMS,它使用 TinyMCE 编辑器作为可视化编辑器。它的CSS编辑很奇怪,因此ul-lists不会显示子弹,段落之间也没有任何空格。
是否有一种简单方便的方法来更改我无权访问的服务器上特定CSS文件中定义的外观?我需要在{{1}中覆盖这些属性}}:
www.site.com/global.css
我相信有一个简单的方法可以使用Greasemonkey,但我对编写脚本并不擅长。哦,我正在使用谷歌浏览器。
答案 0 :(得分:3)
因为你使用TinyMCE,你需要将你的CSS文件加载到TinyMCE iframes头部而不是你的主页面。
使用content_css设置。这是一种覆盖TinyMCE默认CSS的方法。
更新:无法访问服务器文件或TinyMCE配置,您仍然可以访问TinyMCE API。看看load the CSS到您需要的地方的这个选项。您应该将CSS文件放在Internet / Intranet上的某个位置,以便访问它。
// Loads a CSS file dynamically into the current document
tinymce.DOM.loadCSS('somepath/some.css');
// Loads a CSS file into the currently active editor instance
tinyMCE.activeEditor.dom.loadCSS('somepath/some.css');
// Loads a CSS file into an editor instance by id
tinyMCE.get('someid').dom.loadCSS('somepath/some.css');
// Loads multiple CSS files into the current document
tinymce.DOM.loadCSS('somepath/some.css,somepath/someother.css');
Update2 :可以将CSS字符串加载到iframe头中。对于此用法类似于以下 userscript :
// ==UserScript==
// @name YOUR_SCRIPT_NAME
// @match http://YOUR_SERVER.COM/YOUR_PATH/*
// ==/UserScript==
var css_to_add = 'p { margin: 10 px; }'; // example
var iframe_id = 'your_editor_id' + '_ifr'; // place your editor id here+'_ifr'
with(document.getElementById(iframe_id).contentWindow) {
var h = document.getElementsByTagName("head");
if (!h.length) return;
var newStyleSheet = document.createElement("style");
newStyleSheet.type = "text/css";
h[0].appendChild (newStyleSheet);
try {
if ( typeof newStyleSheet.styleSheet !== "undefined" ) {
newStyleSheet.styleSheet.cssText = css_to_add;
}
else {
newStyleSheet.appendChild( document.createTextNode ( css_to_add ) );
newStyleSheet.innerHTML = css_to_add;
}
}
catch(e){}
}
将代码保存为MyCSSFix.user.js
,然后按照these instructions将其安装在Chrome中(在编辑指定的地点后,请参阅详细信息)。
答案 1 :(得分:0)
添加到标记内联的属性应覆盖以前加载的样式表声明。
<p style="margin:0px;"></p>
应覆盖global.css
中的任何p边距样式答案 2 :(得分:0)
使用!important
ul { list-style-type: square !important; }