开发者

Using direct HTML tags instead of div.class

开发者 https://www.devze.com 2023-02-13 16:52 出处:网络
I have some special tags on my blogsite which need to be as simple as pos开发者_Go百科sible so that my colleges who don\'t know anything about HTML can use it. For example

I have some special tags on my blogsite which need to be as simple as pos开发者_Go百科sible so that my colleges who don't know anything about HTML can use it. For example

<question>...</question>

and

<answer>...</answer>

and then these are styled in CSS. It's far easier for HTML-idiots than to use the <div class="answer">...</div> format.

I've just found out IE8 is displaying it all wrong while Firefox and Chrome do it right. Is that expected or am I doing something wrong? Do you know of any hack to fix this since there are tons of blogsposts I'll have to manually change otherwise!!


You want to create <question>...</question> etc.

These are not HTML (not even HTML5), and you will struggle to get browsers to understand them reliably.

A quick tip that might help you:

You say you've got it working in all browsers except IE. If so, you might be able to hack IE to get it working as well, using a technique similar to the hacks like HTML5Shiv that are being used to get IE to work with the new HTML5 tags. These use Javascript to create a DOM element with the new tag name, after which IE suddenly starts to recognise that tag as being valid HTML.

It might just work. But be aware that it is a hack, and it only targets IE. And since you're using non-standard tags, you also have no way of knowing what will happen in the future in terms of it breaking browsers, even if they work now. (in fact, I would say the worse case scenario would be if one of the tags you've invented is added to the HTML standard at a later date, because then you'll start getting weird layout glitches as it gets added to the default stylesheet)

If you can get it working that way, then well done. But consider yourself warned that it's not good practice.

What you have actually asked for is not HTML, but XML markup. This is perfectly fine, but shouldn't be put directly into a web page in the way you're hoping.

There are a number of well-documented ways to get raw XML code into a browser.

One option is to use XSL to transform it into valid HTML. Another way would be to load it into a DOM object in Javascript and process it using a script. (this is where the 'X' comes in 'Ajax').

My guess is that a simple XSL transformation would do the trick for you. (In fact, it sounds like your use case might be simple enough that even just basic string replacement might suffice for the same end result). You can get your colleauges to create the code using <whatever> <tags> <they> <want>, and you write a script that parses it and converts it to regular HTML prior to merging it with the rest of the page.

In the long term, this would probably be a far better solution than the hack I've described above.

Hope that helps.


I don't know if this answer fits your needs but imho using custom html tags is basically NOT using HTML. Therefore the absence of compatibilty. If you need to render data in HTML wouldn't be better using XML + XSLT?

You can find guides on w3schools


You can't add new elements like that. HTML has some fixed elements that browsers understand, but if you add your own, browser don't know what to do with them.

HTML5 has some new elements you can maybe find useful : http://www.w3schools.com/html5/html5_new_elements.asp but this won't work with older browser without some kind of javascript to fix things. For example http://remysharp.com/2009/01/07/html5-enabling-script/

However, if you really want to add new tags, it is possible to do so and then "modify" them via javascript to known tags (actually it's what the html5 enabling script of IE do), but it won't be possible to apply CSS easily to the new tags.

In short, I strongly advise against adding new tags. It's not that hard to understand something like <div class="answer">.


sounds like you want to write XML and convert to HTML using XSLT. This is an old tutorial (includes defining an DTD), but a further web search will garner more results that might suit


here you go fella:

http://net.tutsplus.com/tutorials/html-css-techniques/how-to-make-all-browsers-render-html5-mark-up-correctly-even-ie6/

You need to use createElement :)

0

精彩评论

暂无评论...
验证码 换一张
取 消