dazhifu 2019-07-01
引用MDN解释:content: attr(data-text);
是CSS中引用的HTML元素的属性名称。
p data-foo="hello">world</p>
[data-foo]::before { content: attr(data-foo) " "; }
输出 //hello world
.box span:nth-child(odd) { transform: translateY(-100%); } .box span:nth-child(even) { transform: translateY(100%); }
<span data-text="N">N</span> //html .box span::before { content: attr(data-text); position: absolute; // 脱离文档流 color: red; } .box span:nth-child(odd)::before { transform: translateY(100%); } .box span:nth-child(even)::before { transform: translateY(-100%); }
.box:hover span { transform: translateY(0); }