spr*_*aff 54 css pseudo-element
这是一个小提琴.
<p>foo <a class="infolink" href="#">bar</a> baz</p>
Run Code Online (Sandbox Code Playgroud)
和
a.infolink::before
{
content: '?';
background: blue;
color: white;
width: 20ex;
height: 20ex;
}
Run Code Online (Sandbox Code Playgroud)
'?' 出现,但显然没有20ex大小.为什么不?在Firefox和Chrome中测试过.
adr*_*ift 99
在::before
和::after
伪元素实际上是display: inline;
默认.
将显示值更改inline-block
为宽度和高度生效:
a.infolink::before {
content: '?';
display: inline-block;
background: blue;
color: white;
width: 20px;
height: 20px;
}
Run Code Online (Sandbox Code Playgroud)
小智 6
如果容器中有图像或 CSS空白,请使用此选项:nowrap; 财产
body::before{
content:url(https://i.imgur.com/LJvMTyw.png);
transform: scale(.3);
}
Run Code Online (Sandbox Code Playgroud)