为什么表格字体垂直中心在css中不起作用?

时间:2016-10-28 04:12:21

标签: html css css3

我想设置表格字体垂直居中,但如果它不像我在CSS中设置的效果那样:

.table-display th {
    height: 20px;
    font-size:13px;
    text-align:center;
    vertical-align:middle
}

和html是:

<table id="rule-table"  class="table table-display table-striped  jambo_table" border="1" style="margin-bottom: 5px">
        <thead>
            <tr class="headings">
                <th>Name</th>
......

但是如果我在html而不是css中设置vertical-align样式,它就会生效:

<table id="rule-table"  class="table table-display table-striped  jambo_table" border="1" style="margin-bottom: 5px">
        <thead>
            <tr class="headings">
                <th style="vertical-align:middle;">Name</th>
  ......

问题是什么?

2 个答案:

答案 0 :(得分:0)

您可以在!important课程中使用css或尝试以下代码,

.table-display> thead> tr > th {
    height: 20px;
    font-size:13px;
    text-align:center;
    vertical-align:middle !important;
}

答案 1 :(得分:0)

你只需要在CSS文件中给予!important即可。这将覆盖其他CSS。