简体   繁体   English

表格单元格中的Unicode符号无法CSS的垂直对齐?

[英]Unicode symbol in table cell fails vertical-align of CSS?

Every time I have a unicode symbol in one table cell, 每当我在一个表格单元格中使用unicode符号时,

vertical-align: middle;

in my CSS stops working. 在我的CSS停止工作。 As a result, the text "floats higher" than middle. 结果,文本“浮动到中间”。

在此处输入图片说明

Notice how text in the upper row is vertically aligned in the middle, whereas Sun Jun 4 23:52:31 2017 in the lower row floats higher than middle because of the folder unicode symbol. 请注意,上一行中的文本如何在中间垂直对齐,而下一行中的Sun Jun 4 23:52:31 2017由于文件夹unicode符号的缘故比中间浮动。


Relevant part of CSS CSS的相关部分

table, td, th {
    border: 2px solid #D0D0D0;
}

table {
    border-collapse: collapse;
}

td {
    vertical-align: bottom;
}

Relevant part of HTML HTML的相关部分

<td><a href="foo" style="text-decoration: none">&#x1f4c2;&emsp;viz_coreOpt_3D</a><span style="float:right;">&emsp;&emsp;Sun Jun 4 23:52:31 2017</span></td>

The folder icon is the reason that one line in height exceeds the other. 文件夹图标是一行的高度超过另一行的原因。 I suggest to set the line height not less than the height of the icon. 我建议将线高设置为不小于图标的高度。

 table, td, th { border: 2px solid #D0D0D0; } table { border-collapse: collapse; } td { line-height: 1.5em; vertical-align: bottom; } 
 <table> <tr> <td> <a href="foo" style="text-decoration: none">&#x1f4c2;&emsp;viz_coreOpt_3D</a> <span style="float:right;">&emsp;&emsp;Sun Jun 4 23:52:31 2017</span> </td> </tr> </table> 

Are you using the tag? 您在使用标签吗? You should be as you need to let the table know how to separate your rows. 您应该使表知道如何分隔行。

your table setup in html should look something like this: 您在html中设置的表格应如下所示:

<table>
   <thead> <!-- this is optional -->
      <tr>
         <th></th>
         <th></th>
         <th></th>
      </tr>
   </thead>
   <tbody> <!-- once again this is optional -->
      <tr>
         <td></td>
         <td></td>
         <td></td>
      </tr>
   </tbody>
</table>

this will give you a table with two rows. 这将为您提供两行的表格。 One a header row and one a normal row. 一个标题行,一个普通行。 if you want them to be aligned within the boxes you can center the text with text-align: center; 如果您希望它们在框中对齐,则可以使用text-align来使文本居中: to the middle of the cell width wise and then use vertical-align: middle; 到单元格宽度的中间,然后使用vertical-align:middle; to make it align vertically within the cell of the table. 使它在表格的单元格内垂直对齐。

what is causing the problem with your initial solution is the use of float. 最初的解决方案引起问题的原因是使用float。 This will move it to the right and the top of the element because float 这将使其移到元素的右侧和顶部,因为float

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

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