I have a column where some users are not entering spaces (i.e.: .........................................) and it is stretching my TD column.
我有一个列,其中一些用户没有输入空格(即:.................................... .....)它正在拉伸我的TD专栏。
Is there a way to force line breaks in html with a simple option? If not, I think I am going to have to break the line up myself, which would not be optimal, as I would have to determine the best places to break a line, and I don't want to do that.
有没有办法用简单的选项强制html中的换行符?如果没有,我想我将不得不打破自己的阵容,这不是最佳的,因为我必须确定打破一条线的最佳位置,我不想那样做。
I am looking for something that will work in the 3 main browsers (ie/firefox/safari)
我正在寻找可以在3个主要浏览器中工作的东西(即/ firefox / safari)
Here is my code:
这是我的代码:
<td valign="top">
<br>
<strong><?php echo $common->stripHtml($row['one_liner']); ?></strong>
<br>
<hr>
<?php
if (strlen($row['self_description']) > 240)
{
echo substr($common->stripHtml($row['self_description']), 0, 240)."... <a href='viewprofile.php?i=".$row['user_id']."'>more</a>";
}
else
{
echo $common->stripHtml($row['self_description']);
}
?>
</td>
7 个解决方案
#1
A fixed-width cell combined with hiding overflow content should do the trick
一个固定宽度的单元格与隐藏溢出内容相结合应该可以解决问题
The CSS:
table {
table-layout:fixed;
}
table td {
overflow:hidden;
}
Targeting this HTML:
定位此HTML:
<!-- This width specification ought to be in the top-most <td> or <th> -->
<td width="100" >...</td>
#2
While you could manually add line breaks with PHP, you can also use the "overflow" CSS property to determine how the cell should display its data.
虽然您可以使用PHP手动添加换行符,但您也可以使用“溢出”CSS属性来确定单元格应如何显示其数据。
If you set the overflow to "auto", a scrollbar should appear within the cell, and if you set the overflow to "hidden", the contents will be hidden beyond the width you have set.
如果将溢出设置为“自动”,则单元格中应显示滚动条,如果将溢出设置为“隐藏”,则内容将隐藏超出您设置的宽度。
#3
"as I would have to determine the best places to break a line, and I don't want to do that."
“因为我必须确定打破界限的最佳位置,我不想这样做。”
You've hit the nail on the head there, HTML is equally unable to determine the best place to break the line. Maybe as you know the likely values you can determine a set of rules for allowing breaks.
你已经在那里击中了钉子,HTML同样无法确定打破这条线的最佳位置。也许你知道可能的值,你可以确定一组允许休息的规则。
I would choose a fixed width font to display the text and then insert a break after a fixed number of chars.
我会选择固定宽度字体来显示文本,然后在固定数量的字符后插入一个中断。
#4
You could use the CSS overflow property on the table cell, but this will not force a line break.
您可以在表格单元格上使用CSS overflow属性,但这不会强制换行。
You could insert some
你可以插入一些
­
entities, but browser support is patchy.
实体,但浏览器支持是不完整的。
The best solution would be a regex to break up any continuous sequence of 20 characters by inserting a space. It won't look pretty, but it's better than throwing it all out of line.
最好的解决方案是通过插入空格来分解任意连续20个字符序列的正则表达式。它看起来不会很漂亮,但它最好不要把它全部扔掉。
#5
No css property can break lines without white spaces.
没有css属性可以打破没有空格的行。
By combining a "width:xxx", an "overflow:hidden" and a "table-display:fixed", you can hide unwanted content in your cells.
通过组合“width:xxx”,“overflow:hidden”和“table-display:fixed”,您可以隐藏单元格中不需要的内容。
#6
Another "fix" could be to use Javascript. When that particular input-element's .blur() event is raised, insert breaks at every xth char, or after every xth word. I personally wouldn't call this a "great" solution though.
另一个“修复”可能是使用Javascript。当引发特定的input-element的.blur()事件时,在每个第x个char或每个第x个单词之后插入break。我个人不会称之为“伟大”的解决方案。
Then again, I'm assuming you have the ability to monitor the submissions coming through your site. If this is the case, then you can manipulate the data via PHP/C# - which would be the ideal method.
然后,我假设您有能力监控通过您的网站提交的提交内容。如果是这种情况,那么您可以通过PHP / C#操作数据 - 这将是理想的方法。
#7
Use fixed width cells?
使用固定宽度的细胞?
<td valign="top" width="100px">
#1
A fixed-width cell combined with hiding overflow content should do the trick
一个固定宽度的单元格与隐藏溢出内容相结合应该可以解决问题
The CSS:
table {
table-layout:fixed;
}
table td {
overflow:hidden;
}
Targeting this HTML:
定位此HTML:
<!-- This width specification ought to be in the top-most <td> or <th> -->
<td width="100" >...</td>
#2
While you could manually add line breaks with PHP, you can also use the "overflow" CSS property to determine how the cell should display its data.
虽然您可以使用PHP手动添加换行符,但您也可以使用“溢出”CSS属性来确定单元格应如何显示其数据。
If you set the overflow to "auto", a scrollbar should appear within the cell, and if you set the overflow to "hidden", the contents will be hidden beyond the width you have set.
如果将溢出设置为“自动”,则单元格中应显示滚动条,如果将溢出设置为“隐藏”,则内容将隐藏超出您设置的宽度。
#3
"as I would have to determine the best places to break a line, and I don't want to do that."
“因为我必须确定打破界限的最佳位置,我不想这样做。”
You've hit the nail on the head there, HTML is equally unable to determine the best place to break the line. Maybe as you know the likely values you can determine a set of rules for allowing breaks.
你已经在那里击中了钉子,HTML同样无法确定打破这条线的最佳位置。也许你知道可能的值,你可以确定一组允许休息的规则。
I would choose a fixed width font to display the text and then insert a break after a fixed number of chars.
我会选择固定宽度字体来显示文本,然后在固定数量的字符后插入一个中断。
#4
You could use the CSS overflow property on the table cell, but this will not force a line break.
您可以在表格单元格上使用CSS overflow属性,但这不会强制换行。
You could insert some
你可以插入一些
­
entities, but browser support is patchy.
实体,但浏览器支持是不完整的。
The best solution would be a regex to break up any continuous sequence of 20 characters by inserting a space. It won't look pretty, but it's better than throwing it all out of line.
最好的解决方案是通过插入空格来分解任意连续20个字符序列的正则表达式。它看起来不会很漂亮,但它最好不要把它全部扔掉。
#5
No css property can break lines without white spaces.
没有css属性可以打破没有空格的行。
By combining a "width:xxx", an "overflow:hidden" and a "table-display:fixed", you can hide unwanted content in your cells.
通过组合“width:xxx”,“overflow:hidden”和“table-display:fixed”,您可以隐藏单元格中不需要的内容。
#6
Another "fix" could be to use Javascript. When that particular input-element's .blur() event is raised, insert breaks at every xth char, or after every xth word. I personally wouldn't call this a "great" solution though.
另一个“修复”可能是使用Javascript。当引发特定的input-element的.blur()事件时,在每个第x个char或每个第x个单词之后插入break。我个人不会称之为“伟大”的解决方案。
Then again, I'm assuming you have the ability to monitor the submissions coming through your site. If this is the case, then you can manipulate the data via PHP/C# - which would be the ideal method.
然后,我假设您有能力监控通过您的网站提交的提交内容。如果是这种情况,那么您可以通过PHP / C#操作数据 - 这将是理想的方法。
#7
Use fixed width cells?
使用固定宽度的细胞?
<td valign="top" width="100px">