html - 如何使用 CSS3 获取文档的标题

标签 html css

我想使用 CSS3 选择器“content”向一些 HTML 添加一些文本,例如文档的标题,我该怎么做?

最佳答案

你不能用纯 CSS 实现它。 Content 属性值只能是以下之一:

content: normal                                /* Keywords that cannot be combined with other values */ content: none
content: 'prefix'                              /* <string> value, non-latin characters must be encoded e.g. \00A0 for   */
content: url(http://www.example.com/test.html) /* <uri> value */
content: chapter_counter                       /* <counter> values */
content: attr(value string)                    /* attr() value linked to the HTML attribute value */ 
content: open-quote                            /* Language- and position-dependant keywords */ content: close-quote
content: no-open-quote content: no-close-quote
content: open-quote chapter_counter            /* Except for normal and none, several values can be used simultaneously */
content: inherit

参见 https://developer.mozilla.org/en-US/docs/Web/CSS/content了解更多详情。

使用attr只能抓取当前元素的属性。

但是你可以像这样添加data属性:

<style>
.article-title:before{
    content:attr(data-mytag);font-size:0.5em;margin-right:1em}
</style>
<span data-mytag="Tips here" class="article-title">1</span>

关于html - 如何使用 CSS3 获取文档的标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20727446/

相关文章:

javascript - 对具有数组的 Son 数据进行 Angular ng-repeat

定位的 CSS 简写

html - 如何从中心创建 CSS 渐变?

javascript - jQuery.slideDown 立即完成

html - CSS float 和文本对齐仅作为内联使用

javascript - 如何仅使用 javascript 显示此数组 onchange 的第二列中的内容

javascript - 如何使用哈希标签 ("a name") 转到页面上的位置但在顶部占固定元素?

css - 通过 css 悬停时的 ASP.Net 图像

css - 使用 Reactstrap : Unable to apply CSS styles to image for CarouselItem and how to use div instead of image

jquery - 带有选项卡的 Bootstrap div 在页面加载时自动显示第二个选项卡