html - TD 与 [空白 :no-wrap] is not working as expected?

标签 html css html-table

<分区>

我有一张 table :

enter image description here

请看正确的TD。

黄色的 div 应该有它的高度(强制)。我需要垂直对齐 checkbox + SPAN

所以我把它们都写成:float:left玩过margin-top .

但是当我减小浏览器宽度时,SPAN正在下降:

enter image description here

我已经放了 no-wrap。

我不在乎文本 (td#2) 会被换行我只需要 check-box + span会在一起——永远在一起。
而且我不能使用 width在包装 div 上导致 Yes这里是英文的,但它是一个多语言网站。所以我需要文本适合其原始长度。

我该怎么做才能使这两个元素都不会被包装?

这里是 jsbin Here it is

td{
  border:solid 1px green;
}

.myCheck{
  float:left;
  margin-top:16px;
}


.mySpan{
  float:left;
  margin-top:12px;
}
<table style='width:100%;' cellspacing=0 cellpadding=0>
  <tr>
    <td>
      1
    </td>
    <td>Lorem ipsum dolor sit amet, consectetur adipisicing tempor incididunt ut labore et 
    </td>
    <td style='white-space:nowrap;'>
      <div style='white-space:nowrap; height:50px;background-color:yellow;float:left;'>
        <input type='checkbox' class='myCheck' />
        <span  class='mySpan'>Yes</span>
      </div>
    </td>

  </tr>
</table>

问题来了:

enter image description here

在 Firefox 中它确实包装了它,但在 Chrome 中它没有(它应该是这样)。

最佳答案

试试这个:http://jsbin.com/oquniq/26/edit

<td style='white-space:nowrap;'>
  <label>
    <input type='checkbox' />
    <span class='mySpan'>
      Yes
    </span>
  </label>
</td>

并使用position:relative调整文本的垂直对齐

.mySpan
{
  position:relative;
  top:-2px;
}

关于html - TD 与 [空白 :no-wrap] is not working as expected?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14923123/

相关文章:

javascript - Angularjs 中的侧滑条

css - 并排表格在 Outlook 中不起作用

html - 为什么这些 block 元素在同一行?

html - 重新排列移动表格中单元格的顺序

java - 使用 Thymeleaf 创建在新窗口/标签页中打开的链接

javascript - php显示登录状态消息不更新

jquery - 防止多次点击,直到记录被删除

mysql - 是否可以直接从网页上的表更新 MySQL 表?

php - 如何转义 MYSQL 查询中的引号?

php - 使用 radio select php 更新 mysql