是否可以通过浏览器搜索CSS生成的内容? [英] Is it possible to make CSS generated content searchable by a browser?

查看:175
本文介绍了是否可以通过浏览器搜索CSS生成的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行一个网站,使用CSS伪元素在这里和那里插入文本。其中一个插入一个CSS计数器的值(因此,将需要相当大的重新设计系统来做这没有 CSS文本注入)。具体的CSS规则是:

I run a website that uses CSS pseudo-elements to insert text here and there. One of them inserts the value of a CSS counter (whereupon it would require considerable re-engineering of the system to do this without CSS text injection). The specific CSS rule is:

.num_defn .theorem_label:after {
    content: " " counter(definition, decimal);
    counter-increment: definition;
}

,并将定义 strong>定义1 (说)。

and this converts "Definition" to "Definition 1" (say).

但是,注入的文本不能由浏览器搜索。它没有看到 1 :如果我搜索定义1,然后它找不到它,如果我搜索定义。无论定义文本是什么,那么浏览器会高亮显示除了插入的 1 之外的行。因此,如果您将粗体文字设为突出显示,它将如下所示:

However, the injected text is not searchable by the browser. It doesn't see the 1: if I search for "Definition 1" then it doesn't find it, and if I search for "Definition. Whatever the definition text was" then the browser happily highlights the line except for the inserted 1. So if you imagine the bold text as the highlighting, it would look like:

定义 1 。无论定义文字

这不太理想!人们喜欢通过他们的数字来引用定义,并且说看在页面XYZ上的定义1(在超链接不可用的上下文中 - 奇怪,我知道,但它确实发生)。

This is not ideal! People like to refer to definitions by their number and to say "Look at Definition 1 on the page XYZ" (and in contexts where hyperlinks are not available - strange, I know, but it does happen).

因此:


  1. 我有什么办法在服务器端指定注入的文本searchable?

  2. 如果没有,在浏览器端是否有简单方式启用这项功能?

  1. Is there any way that I, on the server end, can designate the injected text as "searchable"?
  2. If not, is there a simple way at the browser end that this can be enabled?

推荐答案

据我所知,没有办法。你可能可以使用JS来访问这些信息,但它会是一些黑客的事情。

As far as I know there is no way. You could probably use JS to access that information, but it would be some sort of "hack" thing to do.

当我们考虑HTML和CSS的目的时,我认为这很有意义。正如你可能知道的HTML是用来描述内容的语义,而CSS是用来控制页面的外观。所以简而言之,如果你添加任何文本到你的页面使用CSS,它应该只是纯粹为了风格的目的。

And I think it sort of makes sense, when you think about the purpose of HTML and CSS. As you may know HTML is meant to describe the semantic meaning of the content, while CSS is meant to control the appearance of the page. So in short if you add any text at all to your page using CSS it should only be there purely for stylistic purposes.

如果它是实际的文本,应该是什么意思,您网站的访问者需要将其直接作为HTML在您的网站中。

If it is actual text that should mean something to you site visitor you need to have it in your site directly as HTML.

同样,这样做违反了最佳做法。因为如果你禁用CSS,一些内容会消失。

As well the way you did this goes against best practices. Because if you were to disable to CSS, some of the content would disappear.

这篇关于是否可以通过浏览器搜索CSS生成的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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