简体   繁体   English

vertical-align:middle在twitter bootstrap中没有表行rowpan

[英]vertical-align: middle is not working in twitter bootstrap with table rowspan

I'm using Twitter Bootstrap 3.x and I've got a table where a cell has rowspan="2". 我正在使用Twitter Bootstrap 3.x,我有一个表格,其中一个单元格的行数为“2”。 Here is the table row: 这是表格行:

<tr>
    <td rowspan="2" class="critical">
        <a href="#"><span class="glyphicon glyphicon-check white"></span></a>
    </td>
    <td colspan="2" class="col-xs-8 col-md-10">
        <b><a href="#">Title</a></b>
    </td>
</tr>
<tr>
    <td class="col-xs-8 col-md-10">
        <em><small>12/07/2014</small></em> - <a><span class="glyphicon glyphicon-paperclip"></span></a></small>
    </td>
    <td class="col-xs-4 col-md-2">
        <em><small  class="pull-right"><a href="#" class="black">Some name</a></small></em>
    </td>
</tr>

I've been looking trough StackOverflow for these solutions: 我一直在寻找StackOverflow这些解决方案:

  • Use Bootstrap 3 vert-align class (which I couldnt find in docs but someone said its added) 使用Bootstrap 3 vert-align类(我在文档中找不到但有人说它已添加)
  • Use line-height instead 请改用line-height
  • Add CSS vertical-align: middle 添加CSS vertical-align:middle
  • Vertical-align: baseline 垂直对齐:基线
  • ......... .........

I've tried everything, and looking at Chrome dev console, everytime I add line-height or vertical-align: middle, it appears stroked and isn't applied. 我已经尝试了一切,并且看着Chrome开发控制台,每当我添加行高或垂直对齐:中间时,它会出现描边并且不会应用。 Tried also with !important but didnt work either. 也试过!重要,但也没有工作。

I'd like to know if there is something preventing the rowspan cell to be aligned in middle, if it's due to rowspan (which is the most probable issue since the example's people have provide in JSFiddle vertical-align: middle works like a charm). 我想知道是否存在阻止rowspan单元格在中间对齐的东西,如果它是由于rowspan(这是最可能的问题,因为该示例的人在JSFiddle中提供vertical-align:middle就像魅力一样) 。

If there is any extra data needed Ill update the thread. 如果需要任何额外数据,请更新线程。 Thanks in advance! 提前致谢!

Bootstrap uses selector like (shortened): Bootstrap使用选择器(缩短):

.table>tbody>tr>td {
    vertical-align: top;
}

So it has bigger priority that your single class selector ( .vertical-center ). 因此,它的单一选择器( .vertical-center )具有.vertical-center优先级。 So use either more specific selector or !important 所以使用更具体的选择器或!important

.vertical-center {
    vertical-align: middle !important;
}

In regards to the following HTML you would like to vertically align - 关于以下HTML,您希望垂直对齐 -

HTML HTML

<tr>
    <td rowspan="2" class="critical"> <a href="#" class="aa"><span class="glyphicon glyphicon-check white"></span></a>

    </td>
    <td colspan="2" class="col-xs-8 col-md-10"> <b><a href="#">Title</a></b>

    </td>
</tr>

Add the following CSS to allow for the element within the td tag to become vertically aligned. 添加以下CSS以允许td标记内的元素垂直对齐。 I have named the class aa and stuck it inside of the anchor tag in the first td tag. 我将类命名为aa并将其粘贴在第一个td标记中的anchor标记内。

CSS CSS

.aa {
    vertical-align:middle;
}

DEMO JSFiddle DEMO JSFiddle

Okay so I managed to fix it. 好的,所以我设法修复它。

I changed the code to 我将代码更改为

<td rowspan="2" class="critical">
    <div class="input-group-addon">
        <a href="#"><span class="glyphicon glyphicon-check white"></span></a>
    </div>
</td>

and I could finnally manage to vertically align it. 我可以最终设法垂直对齐它。 i can't provide more accurate reasons for why this works, but if you are having this problem with bootstrap you can aftwerwards use abit of CSS to resize the TD to your necessities. 我无法提供更准确的理由说明为什么会这样,但如果你遇到这个问题,你可以使用CSS的abit来调整TD的大小以满足你的需求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM