0

In my website, the users have to enter markdown in a textarea, for which I am using a markdown editor. The problem is: it uses icomoon font, and my websites too. Both uses the same class to define the fonts, but not both uses the same icons. The question is simple: is there a way to define the editor.css for a special div?

Like that:

<div css="editor.css"></div>
E_net4
  • 27,810
  • 13
  • 101
  • 139
Vinz243
  • 9,654
  • 10
  • 42
  • 86

7 Answers7

3

Give the DIV a Class and then add a CSS file like this:

.markdown
{
color: red;
}

If you import a new css dynamic, the old styles will be overwritten.

Some help, for dynamic css loading: How to apply inline and/or external CSS loaded dynamically with jQuery

Community
  • 1
  • 1
schnawel007
  • 3,982
  • 3
  • 19
  • 27
1

You dont need multiple files. You can give the div an id or class like so

  <div class="div1">
      <span></span
    ...
  </div>

and now in you css you do this

   .div1 span{
        font:(whatever font);
     } 
Kwaasi Djin
  • 125
  • 1
  • 11
1

Namespace your editor styles

You can add a selector that namespaces your editor and allows you to style it:

<div class="editor-style">
  <div id="cool-custom-editor">...</div>
</div>

In your css:

.editor-style .icon-thumbs-up { color: green; }

Using Scoped Styles (needs polyfill)

As mentioned in @adeneo's comment below your question there is the option of using scoped style tags.

Supposing your editor looks like this:

<div id="cool-custom-editor">...</div>

You can apply a specific style using the scoped attribute like so:

<div>
  <style scoped>@import url(editor.css);</style>
  <div id="cool-custom-editor">...</div>
<div>

Caveats

According to can I use the scoped attribute is only natively supported by Firefox 26+.

If you want to use it you will have to polyfill:

Further Reading

hitautodestruct
  • 20,081
  • 13
  • 69
  • 93
0

I don't think so, no. At least not without using any js workarounds. The best solution would be to use kind of namespace for user-specific css classes.

LorDex
  • 2,591
  • 1
  • 20
  • 32
0

No you can't do that.. I think you should solve the conflit by changing the icomoon class names in this file.

Hamza MHIRA
  • 157
  • 1
  • 11
0

OK solved: renaming the classes in editor for icomoon was a lot easier than I dared tough.

Vinz243
  • 9,654
  • 10
  • 42
  • 86
0

not a good way but it can help:

$("[css]").each(function(i){
    var elm = $(this);
    $.when($.get(elm.attr("css"))).done(function(response) {
        var newresponse=response.replace(/(.+{)/gi,".customCss"+i+" $1");
        elm.addClass("customCss"+i);
        elm.before('<style>'+newresponse+'</style>');
    });
});