简体   繁体   English

空格属性CSS

[英]White Space property CSS

I have a following td block which present data as follows: 我有以下td块,其显示数据如下:

My name is Ramya and 
I love football.
I work for ABC Company.

<td style="text-align: left;overflow-wrap:break-word;width:50px;">

@Html.DisplayFor(modelItem => item.Text)

</td>

I want my td to display data like this: 我希望我的td显示如下数据:

My name is Ramya and 
     I love football.
     I work for ABC 
     Company.

Which CSS attribute should I use to achieve the result? 我应该使用哪个CSS属性来获得结果? All the lines which are wrapped should contain some whitespaces. 所有换行应包含一些空格。

[from comments] I want to break the line , where the width of the table cell dictates and once the content is wrapped when it crosses table cell width it should leave some white space and then start the content. [摘自评论]我想打破一行,表格单元格的宽度决定了这一点,一旦内容越过表格单元格的宽度被包装,它应该留一些空白,然后开始内容。

So something like this? 像这样吗?

 td { width:100px; overflow-wrap:break-word; padding-left:20px; text-indent:-20px; text-align:left; background:#fcc; } 
 <table> <tr> <td> My name is Ramya and I love football. I work for ABC Company. </td> </tr> </table> 

padding-left:20px; creates a padding for all the content in the cell, and then text-indent:-20px; 为单元格中的所有内容创建一个填充,然后text-indent:-20px; “drags” the first line back to the left by that same amount. 将第一行“拖动”回左相同的数量。

I think what you're looking for is 我想你要找的是

 td{ white-space: pre;  }

It will preserve any white-space characters written into your paragraphs. 它将保留写入段落中的所有空白字符。

Here's a good article about it: https://css-tricks.com/almanac/properties/w/whitespace/ 这是一篇很好的文章: https : //css-tricks.com/almanac/properties/w/whitespace/

See the MDN documentation here: https://developer.mozilla.org/en-US/docs/Web/CSS/white-space 请在此处查看MDN文档: https : //developer.mozilla.org/en-US/docs/Web/CSS/white-space

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

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