更改 <title> 的内容带有伪元素的元素 [英] Changing content of the &lt;title&gt; element with pseudo-element

查看:63
本文介绍了更改 <title> 的内容带有伪元素的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过'::before'伪元素选择html'title'元素并将'content'属性应用于选择来更改html'title'元素的内容.

To change contents of html 'title' element by selecting it via '::before' pseudo-element and applying 'content' attribute to selection.

我有一个网页:

<html>
<head>
  <title>Some title</title>
  <link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
<body>
  <p>Some paragraph</p>
</body>
</html>

和 css 样式表:

title::before {
  content: "Text";
}
p::before {
  content: "Text";
}

我似乎无法使用 css 样式以这种方式更改 html 'title' 元素的内容,但它适用于 'p' 元素.

I can't seem to be able to change content of the html 'title' element this way with css style, but it works with 'p' element.

我知道有很好的 javascript 库和很好的函数可以很容易地处理这个问题,但我想将这些更改应用到我的 webbrowser 中使用自定义 userstyle.css 提供的外部网页.

I know there is good javascript libraries with good functions which can handle this easily, but i want to apply these changes to external webpage served in my webbrowser with custom userstyle.css.

有可能吗?

推荐答案

title 元素不像其他元素那样在视口上呈现,因为它在头部而不是主体中,所以伪元素不起作用与它.

The title element isn't rendered on the viewport like other elements since it's in the head and not the body, so pseudo-elements aren't going to work with it.

这篇关于更改 <title> 的内容带有伪元素的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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