【发布时间】:2020-01-14 01:19:36
【问题描述】:
由于某种原因,当您添加 dislay: flex; 时,:first-letter 伪元素与 :before 伪元素的组合不起作用。
这应该可以工作,mozilla 他们说:
::before 伪元素和 content 属性的组合可能会在元素的开头插入一些文本。在这种情况下,::first-letter 将匹配此生成内容的第一个字母。
参见:
:first-letter 没有弹性框:
.box:before {
content: "Hello World";
font-size: 30px;
}
.box::first-letter{
font-size: 150%;
}
.box {
width:280px;
height:280px;
border:1px solid #c39f76;
box-sizing:border-box;
text-align: center;
line-height: 280px;
}
<div class="box"></div>
使用弹性框:
正如所见,即使添加了:first-letter{ font-size: 150%; },第一个字母的大小也没有增加。
.box:before {
content: "Hello World";
font-size: 30px;
}
.box::first-letter{
font-size: 150%;
}
.box {
width:280px;
height:280px;
border:1px solid #c39f76;
box-sizing:border-box;
display:flex;
justify-content:center;
text-align: center;
line-height: 280px;
}
<div class="box"></div>
(仅在 chrome 上测试过)
【问题讨论】:
标签: css css-selectors pseudo-element