[英]Display multiple text lines of equal length
I would like multiple lines of text to break/word wrap so it appears in a perfect box. 我希望多行文本打破/自动换行,以便它出现在一个完美的盒子里。 The text isn't a string, rather it's composed of individual chars joined together, as such:
<span>L</span>
文本不是字符串,而是由连接在一起的各个字符组成,如下所示:
<span>L</span>
I've tried this css, but I get the result that you see on the left... 我试过这个css,但是我得到了你在左边看到的结果......
body {
font-family:monospace;
width: 200px;
word-wrap: break-word;
display: inline-block;
}
I've also tried text-align: justify;
我也试过
text-align: justify;
with no success.. 没有成功..
I suppose this is what you want: http://jsfiddle.net/bL50ow0b/1/ ? 我想这就是你想要的: http : //jsfiddle.net/bL50ow0b/1/ ?
text-align: justify
is what you need then. text-align: justify
就是你所需要的。
It's hard to understand what you mean regarding the span vs. string, if you posted your text that would be easier. 如果您发布的文本更容易,那么很难理解您对跨度与字符串的含义。
Both versions work for me in this fiddle: https://jsfiddle.net/eq994mpu/1/ using the following code: 这两个版本都适合我这个小提琴: https : //jsfiddle.net/eq994mpu/1/使用以下代码:
p {
width:50px;
word-wrap:break-word;
}
To achieve this you need to add this code: 要实现此目的,您需要添加以下代码:
body {
width:500px;
text-align: justify;
}
The CSS
answers provided work somewhat, but do not ensure each line is definitely composed of n
characters, thus getting that even line look. CSS
答案提供了一些工作,但不保证每一行肯定由n
字符组成,从而获得均匀的线条外观。 I went with inserting a <br/>
after every n
chars. 我去插入
<br/>
每之后n
字符。 Something like: 就像是:
for (;;) {
if (counter >= n) {
myDiv.appendChild(document.createElement("br"));
counter = 0;
}
counter++;
myDiv.appendChild(span);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.