简体   繁体   English

文字/标签xul xbl的部分中的文字阴影

[英]Text shadow in porition of text/label xul xbl

I have a list of a bunch of names. 我有一堆名字的清单。 As a user types I want to highlight the text matches in the names. 作为用户类型,我要突出显示名称中的文本匹配项。 (aside: if nothing is found i show "No matches for 'rar'"). (此外:如果未找到任何内容,则显示“没有匹配的'rar'”)。

This is my goal graphic mockup: 这是我的目标图形样机:

The user has typed "rar" and it has given the matched "rar"s in the names a red outline. 用户键入了“ rar”,并在名称中为匹配的“ rar”赋予了红色轮廓。 I can accomplish this on the whole label with text-shadow: 0 0 1px red but i am not able to do on portion. 我可以在整个标签上使用text-shadow: 0 0 1px red做到这一点text-shadow: 0 0 1px red但是我不能在一部分上做到。

I've seen content editable divs http://html5demos.com/contenteditable accomplish this. 我已经看到了内容可编辑的div http://html5demos.com/contenteditable完成此操作。 They can give different font colors to ranges. 它们可以给范围提供不同的字体颜色。 The xul label i can replace with xbl html textbox etc. I just can't figure it out though. 我可以用xbl html文本框等替换xul标签。但是我只是想不通。

Thanks 谢谢

They can give different font colors to ranges. 它们可以给范围提供不同的字体颜色。

Those ranges essentially get wrapped into spans or font elements and those get styled. 这些范围实际上被包装为跨度或字体元素,并且被设置了样式。 You can probably accomplish splitting text nodes by creating a Range() , setting its start and end inside the text node and then using range.surroundContents() to wrap it in a temporary node to style. 您可以通过创建Range() ,在文本节点内设置其开始和结束位置,然后使用range.surroundContents()将其包装在要设置样式的临时节点中来完成文本节点的拆分。

Once you don't need the text shadow anymore you can unwrap the text (by simply replacing the wrapper with its content) and normalize the text nodes to restore the original state. 一旦不再需要文本阴影,就可以解开文本(通过简单地用其内容替换包装器)并标准化文本节点以恢复原始状态。

Maybe there is some way to magically create anonymous boxes (such as CSS uses internally for line boxes for example) but I don't know enough to point you in the right direction for that approach. 也许有某种方法可以神奇地创建匿名框(例如CSS在内部将线框用于内部),但我所知还不足以为您指明该方法的正确方向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM