使用 css 或 javascript 将文本包裹在固定 Div 内?
我有tinymce编辑器(textarea)和一个div。每当我在文本编辑器中输入内容时,它都会实时显示在预览 div 上(200px),这看起来类似于 stackoverflow 预览。
我想要实现的是,如果我们输入一个没有空格的单词并且超过200px,我想将其换行到下一行。
我试图找到它,但还没有找到解决方案。我尝试了这个解决方案,我在这里找到
.preview_desc
{
word-wrap: break-word; /* IE>=5.5 */
white-space: pre; /* IE>=6 */
white-space: -moz-pre-wrap; /* For Fx<=2 */
white-space: pre-wrap; /* Fx>3, Opera>8, Safari>3 */
}
它在 IE7 中效果不佳。它添加了左右空间。所以我的 div 变得很宽,如下图
http://img38.imageshack.us/ img38/2650/ie7g.jpg
在IE8中,正确的看起来是这样的。
img35.imageshack.us/img35/3915/ie8a.jpg (请添加 http:// 并查看)
Opera 10 也不能完全正常工作。
然后我也有行数js。如果
var height = document.getElementById('divpreview').clientHeight;
var lines = Math.round(height / 10);
document.getElementById('lines').innerHTML = lines;
if(document.getElementById('divpreview').innerHTML == "")
{
document.getElementById('lines').innerHTML = 0;
}
我们使用上面的CSS代码,它在除IE8和7之外的所有浏览器中从第2行开始计数。
我只想在所有最新的浏览器上工作,即FF2,3,IE7,IE8,Safari,Chrome,Opera(最新)。
I have tinymce editor(textarea) and one div. Whenever I type inside the text editor, it shows at the preview div which is (200px) in real time which is looks alike stackoverflow preview.
What I want to achieve is, if we type one words without space and if exceed 200px, I want to wrap it to the next line.
I tried to find it and I didn't find the solution yet. I tried this solution which I found here
.preview_desc
{
word-wrap: break-word; /* IE>=5.5 */
white-space: pre; /* IE>=6 */
white-space: -moz-pre-wrap; /* For Fx<=2 */
white-space: pre-wrap; /* Fx>3, Opera>8, Safari>3 */
}
It doesn't work well in IE7. It added the left and right space. So my div become so wide like the following image
http://img38.imageshack.us/img38/2650/ie7g.jpg
In IE8, which is correct looks is like this.
img35.imageshack.us/img35/3915/ie8a.jpg (Please add http:// and view)
Opera 10 is not totally working also.
And then I have line count js also. Which is
var height = document.getElementById('divpreview').clientHeight;
var lines = Math.round(height / 10);
document.getElementById('lines').innerHTML = lines;
if(document.getElementById('divpreview').innerHTML == "")
{
document.getElementById('lines').innerHTML = 0;
}
If we use the above css code, it starting count from line 2 in all browsers except IE8 and 7.
I only want to works on all latest browser which is FF2,3,IE7,IE8,Safari,Chrome,Opera (latest).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我可能误解了你的问题,但看起来你所需要的只是一些 CSS,特别是最大宽度(对于所有非白痴浏览器)和带有古怪 IE 表达式的宽度(对于 IE)。
例如,
当你将其与已有的 CSS 结合起来时,看起来它应该可以工作。
I may be misunderstanding your issue, but it seems like all you need is a bit of CSS, specifically a max-width (for all the non-idiotic browsers) and a width with a wacky IE expression (for IE).
For instance
When you combine that with the CSS you already have, it seems like it should work.