添加一个绝对定位的 div(100% 高度/宽度),其中包含 em 大小的字体,用“X”填充它
<div class="deceased">X</div>
将正确展开(并保存图像回调:))
如果您不希望通过将 X 的大小设置得非常大来剪裁 X,您将需要 javascript 在 div 大小更改时调整其大小。
更好的是,您可以使用 :after 伪类添加它并保存额外的 div 和“X”
.deceased:after
{
content:"X";
position:absolute;
left:0px;
top:0px;
width:100%;
height:100%;
font-size: 1000px; // adjust this a little though it will be clipped by the div
text-align: center;
line-height: 100%;
overflow: hidden;
}
或者:before .. 将其放在现有内容的“下方”
.deceased:before
{
content:"X";
position:absolute;
left:0px;
top:0px;
width:100%;
height:100%;
font-size: 1000px; // adjust this a little though it will be clipped by the div
text-align: center;
line-height: 100%;
overflow: hidden;
}
更新
我确实找到了一种只使用 CSS 的方法...
@media all and (min-width: 50px) { .deceased:before { font-size:0.1em; } }
@media all and (min-width: 100px) { .deceased:before { font-size:0.2em; } }
@media all and (min-width: 200px) { .deceased:before { font-size:0.4em; } }
@media all and (min-width: 300px) { .deceased:before { font-size:0.6em; } }
@media all and (min-width: 400px) { .deceased:before { font-size:0.8em; } }
and so on ....
更新 2
包含文本的内联 svg 会将文本缩放到 div 的大小...
.deceased:before
{
content: url('data:image/svg+xml;utf8,<svg>....</svg>');
position:absolute;
left:0px;
top:0px;
width:100%;
height:100%;
overflow: hidden;
}