css - 使用字体时,CSS::before 伪属性可以约束宽度分配吗?

标签 css font-awesome

我正在使用 FontAwesome 字体在我当前的元素中推送图标,并且想在某些标签上使用::before 伪属性。

正如您在下图中看到的,标签的对齐方式已关闭。我希望使用“宽度”属性来解决这个问题,以确保图标在水平方向上占据相同的空间量。

Images not aligned

我目前使用的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/

相关文章:

c# - FontAwesome 未加载到 WebView 中

jquery - 如何使用 jquery 更改 div 填充百分比?

javascript - 更改 Wordpress 网站下拉框中的元素

html - 为什么 Font Awesome 不能在 JSFiddle 中使用 Bootstrap?

css - Font Awesome(在 Chrome 中)的三个警告,即 "integrity mismatch"、 "appropriate ` as` value"和 "request credentials don' t match"

html - 在 Chrome 中刷新后,Font Awesome 图标消失

javascript - 如何在 Bootstrap 4 中单击图标后更改图标?

html - 仅使用 CSS 和 HTML 将 div 从它的 parent 那里移走

javascript - Div 在窗口调整大小时跳出空间

javascript - 我怎样才能使 "Wait, it' s 处理..!”系统?