【发布时间】:2016-11-02 01:27:00
【问题描述】:
我正在开发一个简单的寻呼机(在 Angular 2 中),但我的样式有问题。我在页面设计中使用引导程序,在寻呼机中使用引导程序按钮。我正在使用line-height 将文本垂直居中,效果很好,但我不知道如何将按钮中的文本水平居中。文本始终显示在右侧。我试过text-align: center,我试过引导类text-center,但文字仍然在右边。
我的html很简单:
<div class="pager">
<button class="btn btn-sm" *ngFor="let page of pages">{{page}}</button>
</div>
(对于那些不了解 Angular 2 的人:这将遍历 pages 数组并创建与数组具有值的按钮一样多的按钮,并将这些值用作按钮文本)
我的css(sass):
.pager {
display: inline-block;
margin-left: 8px;
button {
max-height: 18px;
max-width: 18px;
margin-left: 2px;
background: $topBarControlBackground;
color: $topBarColor;
line-height: 50%;
font-size: 80%;
}
}
.pager {
display: inline-block;
margin-left: 8px;
button {
max-height: 18px;
max-width: 18px;
margin-left: 2px;
background: $topBarControlBackground;
color: $topBarColor;
line-height: 50%;
font-size: 80%;
}
}
<div class="pager">
<button class="btn btn-sm" *ngFor="let page of pages">{{page}}</button>
</div>
【问题讨论】:
-
更新你的js代码
-
这里没有任何东西可以工作,因为它是 Angular 2。请删除“运行代码 sn-p”按钮。在这种情况下没有意义。 js 根本不涉及按钮的样式。
-
你试过 text-align: center !important 吗?
-
我没有,但我只是做了,没有任何区别。
-
尝试用 padding 替换 margin-left,我也会创建一个 plnkr 而不是代码 sn-p
标签: css twitter-bootstrap-3 sass