0

I am developing an chat application. The message display is all html, so html tags work for text formatting. I would like it if tags like <red></red> etc. would change the text color. Is there anyway to define new tags like that, or will I just have to replace the fake tags with actual html?

2

3 Answers 3

2

In all modern browsers you can use your own tags in a literal sense (however note that its not valid HTML/XHTML markup):

<red>some red text</red>

Then in CSS:

red { color: red; }

However in IE8 and below you will need to use some JavaScript to allow Internet Explorer to style 'made-up' tags (in the same way that you active the new HTML5 tags such as article, section, etc.

document.createElement('red');

Here is a JSFiddle illustrating the above.

Sign up to request clarification or add additional context in comments.

3 Comments

So if I define document.createElement('red') then I can use the css red { color: red; } and <red> Text </red> and it will work?
I can't get that to work in my application. I am loading an included webPage. I did the document thing, and declared the css stuff. Any idea what's missing?
Ensure the that document.createElement('red') is in the <head> element of the parent (containing) HTML page.
2

No, it's safer to stick to <span class="red"></span>. This is HTML not XML/XLST.

Comments

0

You could use LessCSS which is basically kind of "pre-processor" for CSS. There is also a .NET version.

The preprocessor understands simple variables, built-in functions and similar helper constructs that saves you from writing repetitive code.

An example is:

@brand_color: #4D926F;

#header {
  color: @brand_color;
}

h2 {
  color: @brand_color;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.