我正在使用Yii2的DetailView
小部件,我希望它与中心对齐。我试过了'options' => ['align' => 'center']
,但它没有给我预期的输出。输出如下:
可笑的看起来很糟糕。他们是以DetailView
为中心的任何其他方式吗?
这是没有'options' => ['align' => 'center']
的原始输出:
答案 0 :(得分:1)
I think the easiest way would be to set your options as follows:
'options'=>['class'=>'text-center']
Which makes use of the bootstrap-class which is generally used to center texts. Now your text-centering will be overridden by other default table-styles. In this case you could simply add those lines to your css which will absolutely do the trick:
.detail-view.text-center > tbody > tr > th,
.detail-view.text-center > tbody > tr > td {
text-align: center !important;
}
Voilà. Now both your columns should be centered. The explicit path declaration with the >
-sign is to ensure data nested further within your detail-view will be left as is and not centered.