html - 使用属性选择器在 CSS 伪元素中换行

标签 html css attributes pseudo-element

所以我一直试图在 after 元素中换行,但我遇到了(我认为)一个有趣的怪癖。

#fourth figcaption:before
{
   content: 'Figure \A' attr(title) ' ';
   white-space: pre-wrap;  
}

这按我喜欢的方式工作,我在属性内容之前换行。

当我完全从 attr 获取内容时,换行符停止渲染。

#fifth figcaption:before
{
   content: attr(title);
   white-space: pre-wrap;  
}

你可以在这里看到这个> http://jsbin.com/huyaxifomo/edit?html,css,output

有谁知道为什么这会有所作为?提前致谢。

最佳答案

如果您使用 \A\a 或任何类似的值作为您的 HTML 属性的值只是一个静态值。在您的 CSS 中使用类似以下的内容将不会为您的 content 属性解析此类语法

<div data-stuff="Hello \a World"></div>

和 CSS 一样

content: attr(title); 
/* 
   This will not parse \a as a line break and would rather treat it as 
   a string.
*/

如果您想从 CSS 添加换行符,您需要在样式表中声明 \A 而不是 HTML 属性。因此,类似

content: attr(title) '\A World'; /* works now, as your \A will be parsed by CSS */

关于html - 使用属性选择器在 CSS 伪元素中换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44848962/

相关文章:

javascript - 将过渡应用于 jquery .change 元素

java - 在 Java 1.5 中打印,速度慢?

class - OWL:定义类的属性和成员对象

javascript - 如何在弹出窗口或 iframe 中显示网页?哪个是最佳实践?

javascript - 使 jsFiddle 代码在 FF 和 Chrome 上运行时遇到问题

javascript - 将浮点图另存为图像

html - 缩小图像大小以适合表格单元格,这适用于所有浏览器?

javascript - Google "reCaptcha"有时无法显示/呈现

javascript - 学习 jQuery 的选项卡 + CSS Flexbox。任何人都可以帮助完成这项工作吗?

mySQL 显示具有多次出现的公共(public)属性的行