简体   繁体   English

重新缩放div内容而不调整大小

[英]Re-scaling div content without resize

I am looking for a solution to re-scaling the contents of a div with a fixed width and height. 我正在寻找一个解决方案来重新缩放具有固定宽度和高度的div的内容。 Right now i have a div like so : 现在我有一个像这样的div:

<div id="editor_preview" style="width:360px !important;
                                color:gray;
                                margin-top:40px;
                                position:absolute;
                                overflow:auto;
                                height:190px !important">
</div>

I am loading dynamic HTML content into this div, by the use of CKEditor ( http://ckeditor.com/ ) 我通过使用CKEditor( http://ckeditor.com/ )将动态HTML内容加载到此div中

Since the input text may contain different font sizes, I am looking for a way to downscale the contents on overflow. 由于输入文本可能包含不同的字体大小,我正在寻找一种在溢出时缩小内容的方法。

The way I'm trying right now is using javascript and the zoom function like so : 我现在正在尝试的方式是使用javascript和缩放功能,如下所示:

document.getElementById(ev.editor.name + '_preview').innerHTML = ev.editor.getData();
var container = document.getElementById(ev.editor.name + '_preview');
var i = 99.9;

if (container.scrollHeight > container.clientHeight) {
    while (container.scrollHeight > container.clientHeight) {

        container.style.zoom = i + "%";
        i -= 0.1;
    }
}

However ; 然而; this also decreases the size of the div to match the content. 这也减小了div的大小以匹配内容。 So in short what i want is : 所以简而言之我想要的是:

  • Keep the div size 保持div大小
  • Downscale the content 缩小内容
  • No overflow 没有溢出

Just a shot in the dark here. 只是在黑暗中拍摄。 Seems like you're doing things above my skill level, but what about using rem? 看起来你的工作水平高于我的技能水平,但是使用rem呢? Then controlling it with font-size: 50%;? 然后使用font-size控制它:50%;?

CSS CSS

body{
    font-size: 1rem;
}

#editor_preview{
    font-size: 50%; // control text size here
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM