我有以下html
<!DOCTYPE html>
<html>
<head>
<style>
p.test {
width: 11em;
border: 1px solid #000000;
word-wrap: break-word;
white-space: pre-wrap;
}
</style>
</head>
<body>
<p class="test"> This paragraph contains a very long word: thisisaveryveryveryveryveryverylongword. The long word will break and wrap to the next line.</p>
</body>
如果我更改为&#34; white-space:pre-line&#34;,则显示屏不会显示空格。如何使第一行与文本的其余部分对齐?
答案 0 :(得分:5)
删除空格......
更改
<p class="test"> This
到
<p class="test">This
p.test {
width: 11em;
border: 1px solid #000000;
word-wrap: break-word;
white-space: pre-wrap;
}
<p class="test">This paragraph contains a very long word: thisisaveryveryveryveryveryverylongword. The long word will break and wrap to the next line.</p>
答案 1 :(得分:1)
使用css属性white-space: pre-wrap
代替white-space: pre-line
答案 2 :(得分:0)
只需使用white-space: normal
或不使用white-space
。
p.test {
width: 11em;
border: 1px solid #000000;
word-wrap: break-word;
white-space: normal;
}
&#13;
<p class="test"> This paragraph contains a very long word: thisisaveryveryveryveryveryverylongword. The long word will break and wrap to the next line.</p>
&#13;
答案 3 :(得分:0)
您可以使用javascript代替CSS空格或断字
var ss = "This paragraph contains a very long word: thisisaveryveryveryveryveryverylongword. The long word will break and wrap to the next line.";
document.getElementById('test').innerHTML = ss.replace(/\n/g, '<br/>');
或
document.getElementById('test').innerHTML = ss.replace(/\n/g, '<br>\n');