自定义标签在ie8中不起作用

时间:2011-07-28 06:13:17

标签: css ie8-compatibility-mode

我尝试制作自定义标签,以便用户可以输入显示红色或粗体等字样的文字,例如,当用HTML呈现时,

<rb>text here becomes red and bold</rb> and goes to default here

这会在带有'note'类的div中呈现,并且我有以下css设置

.note rb
{
    color:Red;
    font-weight:bold;
}

它适用于ie9,chrome,firefox,但在ie8中不起作用。我怎样才能让它在那里工作?

2 个答案:

答案 0 :(得分:19)

如果你不介意一点javascript:

<!--[if lt IE 9]>
<script>
document.createElement("rb");
</script>
<![endif]-->

如果你想添加几个元素/标签,你可以:

<!--[if lt IE 9]>
<script>
// bold, italic, underlined, striked
els = ['rb', 'ri', 'ru', 'rs'];
for(i = 0; i < els.length; i++) {
    document.createElement(els[i]);
    }
</script>
<![endif]-->

更新

看起来定义自定义元素的能力在工作中(W3C Working Draft 6 June 2013

一些使用它的项目:

另见:

答案 1 :(得分:0)

为了取悦高级浏览器(IE8及更早版本),我会选择以下内容:

HTML:

<span class="RB">text here becomes red and bold</span> and goes to default here

CSS:

.RB {color:Red; font-weight:bold; }

这针对所有RB类。所以你只需要把所有东西都包在里面

<span class="RB"> </span>

相关问题