调整textarea的大小以垂直适合页面

时间:2016-02-12 15:41:41

标签: html

我正在尝试调整textarea(将被CKEditor替换为精确的形式)以适应整个页面,这是我的HTML代码:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>A Simple Page with CKEditor</title>
        <!-- Make sure the path to CKEditor is correct. -->
        <script src="ckeditor/ckeditor.js"></script>
    </head>
    <body>
        <h1 align="center" style="font-family:Consolas;">AIO HTML WYSIWYG Editor</h1>
        <form>
            <textarea name="editor1" id="editor1" rows="50" cols="80">

            </textarea>
            <script>
                // Replace the <textarea id="editor1"> with a CKEditor
                // instance, using default configuration.
                CKEDITOR.replace( 'editor1' );
            </script>
        </form>
    </body>
</html>

目前的情况如下: Screenshot of the page in firefox 提前致谢! :)

2 个答案:

答案 0 :(得分:0)

JS:

screen.width;
screen.height;

JS:

document.getElementById("someIDofElement").style.width=screen.width-0+'px'; /* -0 not need but if you need you can do -100 or +100 if need*/
    document.getElementById("someIDofElement").style.height=screen.height-0+'px';

答案 1 :(得分:0)

我想这取决于您使用的是哪个版本。你看过http://ckeditor.com/addon/maximize了吗?

此外,您可以尝试使用javascript调用内置最大化功能:

<script>
window.onload = function(){
CKEDITOR.on('instanceReady',
      function( evt )
      {
         var editor = evt.editor;
         editor.execCommand('maximize');
      });
};
</script>

(注意:此代码发布在网络上,我从专家交流中复制了这个特定的代码段)