在Twitter的Bootstrap框架中是否有一组对齐文本的类?
例如,我有一些包含$ total的表格,我希望它们向右对齐……
<th class="align-right">Total</th>
and
<td class="align-right">$1,000,000.00</td>
在Twitter的Bootstrap框架中是否有一组对齐文本的类?
例如,我有一些包含$ total的表格,我希望它们向右对齐……
<th class="align-right">Total</th>
and
<td class="align-right">$1,000,000.00</td>
当前回答
Bootstrap 4有五个类:text left, text center, text right, text justify和text nowrap。
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/> <div class="text-left">Left aligned text.</div> <div class="text-center">Center aligned text.</div> <div class="text-right">Right aligned text.</div> <div class="text-justify">Justified text starts here. The quick brown fox jumps over the lazy dog. Justified text ends here.</div> <div class="text-nowrap">No wrap text starts here. The quick brown fox jumps over the lazy dog. No wrap text ends here.</div>
其他回答
只需添加一个“自定义”样式表,它在Bootstrap的样式表之后加载。所以类定义是重载的。
在这个样式表中声明对齐方式如下:
.table .text-right {text-align: right}
.table .text-left {text-align: left}
.table .text-center {text-align: center}
现在你可以使用td和th元素的“通用”对齐约定了。
如果在Bootstrap 4.5中使用text-sm-right似乎不工作,请考虑可能内容对于表来说太多了,并且表不是在容器的100%(例如col)
使桌子100%宽:
<table class="w-100">
v3.3.5中的引导文本对齐:
<p class="text-left">Left</p>
<p class="text-center">Center</p>
<p class="text-right">Right</p>
CodePen例子
你可以使用下面的CSS:
.text-right {text-align: right} /* For right align */
.text-left {text-align: left} /* For left align */
.text-center {text-align: center} /* For center align */
使用text-align:center !重要。可能有其他的文本对齐css规则,所以!important是重要的。
表格 th, td { 颜色:黑色!重要; border-collapse:崩溃; 背景颜色:黄色! 边框:1px纯黑色; 填充:10 px; Text-align: center ! } <表> < tr > < th > 居中对齐文本 < / th > < / tr > < tr > <td>居中对齐文本</td> <td>居中对齐文本</td> < / tr > 表> < /