css 如何设置小文本区域的高度?

iklwldmw  于 2023-05-02  发布在  其他
关注(0)|答案(7)|浏览(148)

我正在使用以下内容:

<textarea
    data-ui-tinymce="tinymceOptions"
    data-ng-disabled="modal.action=='delete'"
    data-ng-model="modal.formData.text"
    id="inputText"
    rows="20"
    required></textarea>

当tinymce出现的高度只有几厘米。如何在默认值首次出现时更改其高度?
下面是我正在使用的选项列表:

selector: "textarea",           
plugins: [
                        "advlist autolink autosave link image lists charmap print preview hr anchor pagebreak spellchecker",
                        "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
                        "table contextmenu template textcolor paste fullpage textcolor"
                ],

                toolbar1: "bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | styleselect fontselect fontsizeselect",
                toolbar2: "cut copy paste | searchreplace | bullist numlist | outdent indent blockquote | undo redo | code | inserttime preview | forecolor backcolor",
                toolbar3: "table | hr removeformat | subscript superscript | charmap | print fullscreen | spellchecker | visualchars visualblocks nonbreaking template pagebreak restoredraft",

                menubar: false,
                toolbar_items_size: 'small',

                templates: [
                        {title: 'Test template 1', content: 'Test 1'},
                        {title: 'Test template 2', content: 'Test 2'}

]

6jygbczu

6jygbczu1#

从javascript

tinymce.init({
   selector: 'textarea',
   height: 200
});

从html

<textarea style="height: 200px;">
u2nhd7ah

u2nhd7ah2#

你应该在CSS中设置容器对象的高度:

#inputText {
    height : 10000000px;
}
uxh89sit

uxh89sit3#

tinyMCE版本之前4.X那么这段代码就可以工作了

tinyMCE.init({
    ...,
    setup: function(editor) {
        editor.onInit.add(function() {
            var width = editor.getWin().clientWidth;
            var height = 50;

            editor.theme.resizeTo(width, height);
        });
    }
});

tinyMCE版本4。X和之后,那么这段代码就可以工作了

tinyMCE.init({
   setup: function (ed) {
      ed.on('init', function(args) {
         var id = ed.id;
         var height = 25;

         document.getElementById(id + '_ifr').style.height = height + 'px';
      });
   }
});
e4eetjau

e4eetjau4#

对于TinyMCE的全局高度设置,请编辑 www.example.com 项目:

TINYMCE_DEFAULT_CONFIG = {'height': 120}

对于每个小部件的设置,请在表单类中使用mce_attrs

input = forms.CharField(widget=TinyMCE(mce_attrs={'height': 120}))

使用django-tinymce 2测试。7.0.

**在后台:**您可以在为textarea生成的HTML的data-mce-conf属性中看到类似&quot;height&quot;: 120,的字符串。否则,就会出问题。

vptzau2j

vptzau2j5#

对我有效(参见setTimeout部分)

$(function () {
    window.init_tinymce = function (id, custom_config) {
        var textarea = $('#' + id);

        // Default TinyMCE configuration
        var basic_config = {
            mode: 'none',
            plugins: "link",
            menu: 'none',
            toolbar: 'bold | formatselect | link'
        };

        tinymce.init($.extend(basic_config, custom_config));
        ...

        setTimeout(function(){ //wait for tinymce to load
            console.log('timeout');
            $(tinymce.editors[0].iframeElement).contents().find('body')
                .css('min-height', $(tinymce.editors[0].contentAreaContainer).height() * .9);
        }, 1000);
    };
});
j7dteeu8

j7dteeu86#

将此css添加到您的自定义样式表中,否则它将降低所有现有编辑器的高度。

.mce-edit-area iframe {
    max-height: 200px;
}
rkkpypqq

rkkpypqq7#

对于版本6,下面的代码应该可以工作

const wishedHeight = '100px'
// get `editor` from context of callbacks like `init`, `setup`, `loaded`, etc 
editor.editorContainer.style.height = wishedHeight;

相关问题