使用以逗号分隔的关键字突出显示文字 [英] Highlight text by keywords which are separated by comma

查看:136
本文介绍了使用以逗号分隔的关键字突出显示文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用逗号分隔文本,即关键字如下:

I would like to split up text by comma - i.e. keywords are as the following:

keyword1, keyword2, keyword3, keyword4

如何为每个关键字设置一个黑色样式元素, 。有没有一个简单的方法来做到这一点?文本总是动态的,所以我不知道这些关键字会是什么和多少。因此,每个关键字应该有一个框元素。

How can I have a the black style element for each and every keyword that is separated by a comma. Is there an easy way to do this? The text is always dynamic, so I never know exactly what those keywords will be and how many. So each keyword should have a box elements around it.

<span class="keyword-option-black">keyword1, keyword2, keyword3, keyword4</span>

.keyword-option-black {
    color:white;
    background-size:contain;
    margin:10px;
    padding:5px;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    border-radius: 5px;
    background:black;
}


推荐答案

使用Django


  1. 创建一个简单的CSS类来执行突出显示。

  2. 创建自定义将模板视图中的数据拆分为< span class =keyword> A< / span>< span class =keyword> B< / span> 。它采用原始视图输出,并将其解析为已包含跨度的格式。

  1. Create a simple CSS class to perform the highlighting.
  2. Create a custom tag that splits up data in template view into <span class="keyword">A</span><span class="keyword">B</span>. It takes the original view output and parses this into a format that already has the spans included.

这篇关于使用以逗号分隔的关键字突出显示文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆