固定大小的div不应该将数字分成两半

时间:2022-08-14 19:31:57

If I have numbers in a sequence, and those numbers are displayed inside div wrapper with fixed size. How can I prevent those numbers to be break on two digits numbers, for example if number is 45 I do not want to break this number to be 4 at the end of first line and 5 on the beggining of the second line.

如果我在序列中有数字,那么这些数字显示在固定大小的div包装器中。如何防止这些数字在两位数字上中断,例如,如果数字为45,我不希望在第一行末尾将此数字分为4,在第二行的开始时分为5。

for example, given sequence numbers are

例如,给定的序列号是

1 2 3 10 20 45 91 92 93 94

if fixed div size has a width to break this numbers I want to break like this

如果固定的div大小有一个宽度来打破这个数字,我想像这样打破

1 2 3 10 20 45
91 92 93 94

and not

并不是

1 2 3 10 20 4
5 91 92 93 94

2 个解决方案

#1


3  

Use word-break

使用分词

#content{
    width: 45px;
    word-break: keep-all;
}
<div id="content">1 2 3 10 20 45 91 92 93 94</div>

#2


1  

you can try this for sorting

你可以尝试这个进行排序

var points = [40, 100, 1, 5, 25, 10];
points.sort(function(a, b){return a-b});

than use jquery to print in div

而不是使用jquery在div中打印

var text;
jQuery.each(points, function(i, val) {
    text+= val + " ";
});

$('#myDIV').html(text);

#1


3  

Use word-break

使用分词

#content{
    width: 45px;
    word-break: keep-all;
}
<div id="content">1 2 3 10 20 45 91 92 93 94</div>

#2


1  

you can try this for sorting

你可以尝试这个进行排序

var points = [40, 100, 1, 5, 25, 10];
points.sort(function(a, b){return a-b});

than use jquery to print in div

而不是使用jquery在div中打印

var text;
jQuery.each(points, function(i, val) {
    text+= val + " ";
});

$('#myDIV').html(text);