无法为水平 html 滚动框输入长行文本
我想在我的博客上有一个滚动框,以便我可以向读者显示代码。但是,当实际在开头和结尾“div”之间粘贴代码时,实际编写代码内容的输入区域的文本换行意味着我无法输入足够长的文本行,以致水平滚动条无法显示才会真正投入使用。发布帖子时,文本换行会弄乱代码行。应该像这样的滚动条
<div style="width:500px;height:300px;overflow:scroll;
border-width:2px;border-color:000000;border-style:solid;">
12345678910111213141516171819202122232425262728299999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
</div>
包裹文本以产生类似这样的内容(无水平滚动)
<div style="width:500px;height:300px;overflow:scroll;
border-width:2px;border-color:000000;border-style:solid;">
123456789101
112131415161718192021222324252
6272829999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999
999999
</div>
I want to have a scroll box on my blog so that I can show code for my readers. However, when actually pasting the code between the opening and ending "divs" the text wrapping of the entry area where you actually write the content of the code means that I can't enter lines of text that are sufficiently long that the horizontal scroll bar will actually be called into use. The text wrapping mucks up the lines of code when the post is published. A scroll bar that should act like this
<div style="width:500px;height:300px;overflow:scroll;
border-width:2px;border-color:000000;border-style:solid;">
12345678910111213141516171819202122232425262728299999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
</div>
wraps the text to produce something like this ( no horizontal scrolling )
<div style="width:500px;height:300px;overflow:scroll;
border-width:2px;border-color:000000;border-style:solid;">
123456789101
112131415161718192021222324252
6272829999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999
999999
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这只需使用 CSS 即可实现,但从语义上讲,您在代码框中使用了错误的元素。您应该使用
我也将其更改为
overflow:auto
以便滚动条仅在需要时出现。This can be achieved with just CSS, but semantically you are using the wrong element for a code box. You should use
<pre>
instead of<div>
and that will automatically sort out the wrapping. Then you should be wrapping the code in<code>
tags. Live example: http://jsfiddle.net/ddEPB/2/I also changed it to
overflow:auto
so that scrollbars only appear when needed.