我正在使用 FontAwesome 字体在我当前的元素中推送图标,并且想在某些标签上使用::before 伪属性。
正如您在下图中看到的,标签的对齐方式已关闭。我希望使用“宽度”属性来解决这个问题,以确保图标在水平方向上占据相同的空间量。
我目前使用的CSS是
.title::before {
font-family: FontAwesome;
font-size: 1.2em;
margin-right: 5px;
width:35px; // this can be 34523px and still does nothing for the view
}
&.error .title::before {
content: $fa-var-exclamation-circle;
color: $color_error;
}
虽然我知道这个对象是一个字体字形并且有它自己的字体大小。我不想操纵较宽图标的字体大小来适应差异。如上所述,当我按原样应用宽度时,没有任何变化。
这似乎是风格的理性元素。我错过了什么吗?
最佳答案
让我们让它回答:添加
display: inline-block;
到元素 --> http://jsfiddle.net/d72bo9q1/1/
.xxx:before {
content: 'x';
background-color: green;
width: 100px;
display:inline-block;
}
.xxx {
background-color:orange;
}
<div class="xxx">bla bla bla</div>
关于css - 使用字体时,CSS::before 伪属性可以约束宽度分配吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32148815/