大佬教程收集整理的这篇文章主要介绍了javascript – 如何格式化适用于宽限制设备(如iPhone)的长HTML块,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
例如
a very long pre block start here here here here here here here here here here 2nd line with intent 3rd line with intent
如何制作wordwrap,但保留缩进?
e.g. a very long pre block start here here here here here here here here here here 2nd line with intent 3rd line with intent
我不希望有移动设备的滚动条,所以最好有一些方法来自动自动换行句子.
我尝试过的最类似的方法是使用CSS
pre { white-space: pre-line; }
但不完全如我所愿,如上所示.
更新:链接:@L_489_0@
脚本:
var pre = document.getElementById( 'pre' ),sections = pre.textContent.trim().split( '\n' ),paddingPerChar = 9; for( var index=0,html='',padding=0; index < sections.length; index++ ) { padding = ( sections[index].length - sections[index].trim().length ) * paddingPerChar; html += '<div style="padding-left:' + padding + 'px;">' + sections[index].trim() + '</div>'; }; pre.innerHTML = html;
HTML:
<pre id="pre"> 1. a very long pre block start here here here here here here here here here here A. 2nd line with indent long pre block start here here here here here here here here here a. 3rd line with indent B. 4th line th indent long pre block start here here here here here here here her C. 5th line 2. 6th Line </pre>
CSS:
pre { border: 1px solid black; height: 460px; width: 320px; white-space:pre-wrap; }
输出:
以上是大佬教程为你收集整理的javascript – 如何格式化适用于宽限制设备(如iPhone)的长HTML块全部内容,希望文章能够帮你解决javascript – 如何格式化适用于宽限制设备(如iPhone)的长HTML块所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。