简体   繁体   English

`white-space:nowrap`影响宽度

[英]`white-space: nowrap` affects width

I have a table for the file uploader. 我有一个文件上传器的表。 File names might be long, so only the part of the name is displayed with the help of: 文件名可能很长,因此只有名称的一部分显示在以下帮助下:

overflow: hidden;
white-space: nowrap;

Everything works fine for small names (the table is inside the Bootstraps panel borders), but for the big ones I have this: 一切都适用于小名称(表格在Bootstraps面板边框内),但对于大型名称,我有这个: 白色空间:nowrap

All the <td> tags have proportions with the help of col-xs-* , total sum of the * values is 12. If I comment the white-space: nowrap; 所有<td>标签在col-xs-*的帮助下都有比例, *值的总和为12.如果我评论white-space: nowrap; the page looks like: 该页面看起来像: 用white-space:wrap注释掉

I have already checked the box sizes, only the width of the <td> is affected, there are no padding or margin changes. 我已经检查了盒子大小,只有<td>的宽度受到影响,没有填充或边距更改。

Why is that, and how can I fix it elegantly? 为什么会这样,我怎样才能优雅地解决它? Thank you in advance. 先感谢您。

 .table-fixed tbody { height: 200px; overflow-y: auto; width: 100%; float: left; } .table-fixed thead, .table-fixed tbody, .table-fixed tr, .table-fixed td, .table-fixed th { display: block; } .table-fixed tbody td, .table-fixed thead > tr> th { float: left; border-bottom: none; max-height: 40px; min-height: 40px; } .file-name { overflow: hidden; white-space: nowrap; } 
 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/> <div class='col-xs-10 col-xs-offset-1'> <div class='panel panel-default'> <div class='panel-heading'> <span class='help-block'><span translate>Upload files by dragging &amp; dropping or selecting them.</span>&nbsp;<a>Browse to select</a> </span> </div> <table class="table table-fixed"> <tbody> <tr ng-repeat='f in files'> <td class='col-xs-6 file-name'>Long name Long name Long name Long name Long name Long name Long name Long name Long name Long name Long name Long name Long name </td> <td class='col-xs-5'> <div class='progress'> <div class='progress-bar' role='progressbar' aria-valuemin='0' aria-valuemax='100' style='width:50%'></div> <span class="percents">50%</span> </div> </td> <td class='col-xs-1'> <a href>X</a> </td> </tr> </tbody> </table> </div> </div> 

That's because with the automatic table layout , 那是因为自动表布局

the formatted content may span any number of lines but may not overflow the cell box. 格式化的内容可以跨越任意数量的行但可以不溢出单元格框。

So you can solve this by using the fixed table layout instead. 因此,您可以通过使用固定表格布局来解决此问题。 Add the following style to the table box: 将以下样式添加到表格框中:

table-layout: fixed;

The problem is that your table layout is all messed up, with display: block and float: left styles. 问题是您的表格布局全部搞砸了, display: blockfloat: left样式。 So your table-cell s are wrapped inside an anonymous table, which you can't select. 所以你的table-cell被包装在一个你无法选择的匿名表格中。

Either don't mess the table, or add a display: table wrapper. 要么不弄乱表,要么添加display: table wrapper。

.table-fixed tr {
  display: table;
  width: 100%;
  table-layout: fixed;
}

 .table-fixed tbody { height: 200px; overflow-y: auto; width: 100%; float: left; } .table-fixed tr { display: table; width: 100%; table-layout: fixed; } .table-fixed thead, .table-fixed tbody, /*.table-fixed tr,*/ .table-fixed td, .table-fixed th { display: block; } .table-fixed tbody td, .table-fixed thead > tr> th { float: left; border-bottom: none; max-height: 40px; min-height: 40px; } .file-name { overflow: hidden; white-space: nowrap; } 
 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/> <div class='panel panel-default'> <div class='panel-heading'> <input type='button' class='btn btn-danger' value='Abort'></input> <span class='help-block'><span translate>Upload files by dragging &amp; dropping or selecting them.</span>&nbsp;<a>Browse to select</a> </span> </div> <table class="table table-fixed"> <tbody> <tr ng-repeat='f in files'> <td class='col-xs-6 file-name'>Long name Long name Long name Long name Long name Long name Long name Long name Long name Long name Long name Long name Long name </td> <td class='col-xs-5'> <div class='progress'> <div class='progress-bar' role='progressbar' aria-valuemin='0' aria-valuemax='100' style='width:50%'></div> <span class="percents">50%</span> </div> </td> <td class='col-xs-1'> <a href> <fa name="trash" alt="delete" style="color: #FF4136"></fa> </a> </td> </tr> </tbody> </table> </div> 

You Must pass the width for the td 您必须传递td的宽度

.file-name {
  overflow: hidden;
  white-space: nowrap;
 width:300px
}

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

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