Maximizing the height of TinyMCE 4 within a containing element

I am currently in the process of transitioning from TinyMCE 3 to 4.

However, I am encountering difficulties when trying to get TinyMCE to fill its container with 100% height (which was working fine with TinyMCE 3).

Please refer to this fiddle: http://jsfiddle.net/MLJaN/

In an attempt to set the iframe and all its parent elements to 100% height, I utilized the following CSS code. Though not ideal visually, I expected it to work:

 body, html, .mce-tinymce, .mce-edit-area.mce-container, iframe, .mce-container-body.mce-stack-layout
 {
     height: 100% !important;
 }

As observed in the live fiddle, the editor is exactly 34px taller than it should be, which corresponds to the toolbar's height.

The solution provided does function, however, it lacks automatic resizing with the browser and relies on calc(), which has limited support at approximately 79%: http://jsfiddle.net/MLJaN/2/

I am now seeking a pure CSS solution (without using calc() function) to ensure that the entire editor fills its container and can fluidly resize.

Any guidance on achieving this would be greatly appreciated.

Answer №1

Being a hammer can make every problem seem like a nail. There's no need for complicated javascript or jquery here; the tags are designed to do the work for you. All that's required is adjusting the margin on #mcu_31 to account for the height of the toolbar and footer. The code below ensures that TinyMCE is responsive within its containing element.

/*Container, container body, iframe*/
.mce-tinymce, .mce-container-body, #code_ifr {
    min-height: 100% !important;
}
/*Container body*/
.mce-container-body {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
}
/*Editing area*/
.mce-container-body .mce-edit-area {
    position: absolute;
    top: 69px;
    bottom: 37px;
    left: 0;
    right: 0;
}
/*Footer*/
.mce-tinymce .mce-statusbar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
}

This revision accounts for changes in id's due to additions or deletions of menus/toolbars in TinyMCE. It remains effective regardless of modifications made to it.

Answer №2

Utilizing the power of CSS, I successfully tackled this issue by implementing flex-boxes.

<style>
  #main-content, .section-container,.grid-layout, .content-area{
    display: flex;
    flex-direction: column;
    flex: 1;
  }
   .section-container iframe{
    flex: 1;
  }
</style>

By doing so, you eliminate the need to worry about adjusting the dimensions of various elements like the menu-bar.

Check out my JSFiddle demonstration here: https://jsfiddle.net/td3r8j6v/

Answer №3

Moving the calculations from CSS to JavaScript has streamlined the process. This eliminates the need for manual adjustments to the menubar height and ensures compatibility with all browsers, regardless of css calc() support.

function resize() {
    setTimeout(function () {
        // Main container
        var max = $('.mce-tinymce')
              .css('border', 'none')
              .parent().outerHeight();

        // Menubar
        max += -$('.mce-menubar.mce-toolbar').outerHeight(); 

        // Toolbar
        max -= $('.mce-toolbar-grp').outerHeight(); 

        // Random fix lawl - why 1px? no one knows
        max -= 1;

        // Set the new height
        $('.mce-edit-area').height(max);
    }, 200); 
} 

$(window).on('resize', function () { resize(); });

Experience it yourself!

Test it out on jsBin: http://jsbin.com/dibug/2/edit

For further information, check out this gist.

Answer №4

For those of you who prefer vanilla JavaScript over jQuery, below is a snippet of code that achieves the same functionality:

function customResize(){
    var height = window.innerHeight;
    console.log("height = " + height);

    if (document.getElementsByClassName('mce-toolbar-grp')){
        height -= document.getElementsByClassName('mce-toolbar-grp')[0].offsetHeight;
        height -= document.getElementsByClassName('mce-toolbar-grp')[0].offsetTop;
        console.log("height = " + height);
    }
    if (document.getElementsByClassName('mce-statusbar')){
        height -= document.getElementsByClassName('mce-statusbar')[0].offsetHeight;
        console.log("height = " + height);
    }

    height -= 3; // Adjust this value based on your HTML and body margins

    if (document.getElementsByClassName('mce-edit-area')){
        document.getElementsByClassName('mce-edit-area')[0].style.height = height + "px";
        console.log("height = " + height);
    }

}

window.onresize = customResize;
window.onload = customResize;

Answer №5

Need some help with this issue? Here's a tip:

.tox-tinymce{
  height: 100% !important;
}

When an API is not available, using CSS to override styles is a sophisticated way to customize your UI

Answer №6

This solution proved to be the most effective in solving my problem. It combines elements from various top answers.

$(window).on('resize', function () {
    setTimeout(function () {
        var max = $('.mce-tinymce').css('border', 'none').parent().height();
        max -= $('.mce-menubar.mce-toolbar').outerHeight(); 
        max -= $('.mce-toolbar-grp').outerHeight(); 
        max -= $('.mce-edit-area').outerHeight() - $('.mce-edit-area').height();
        $('.mce-edit-area').height(max);
    }, 100); 
});

To ensure proper initialization, add a resize trigger:

tinymce.init({
    selector: '#tinymce',
    height: "100%",
    branding: false,
    statusbar: false,
    setup: function (ed) {
        ed.on('init', function(args) {
            $(window).trigger('resize');
        });
    }
});

Answer №7

With Angular, the solution is to address this particular issue by applying the following method:

@Component({
  selector: 'serta-tinymce',
  template: `<textarea **style="min-height:500px"** id="store-description"></textarea>`,
  styles: []
})

Answer №8

#editor-wrapper {
    max-height: 100%;
}

#editor-wrapper .mce-tinymce.mce-container.mce-panel,
#editor-wrapper .mce-container-body.mce-stack-layout {
    max-height: 100%;
}

#editor-wrapper .mce-edit-area.mce-container.mce-panel.mce-stack-layout-item {
    max-height: calc(100% - 75px); /* 75 represents the height of the tinymce header and footer */
}

#editor-wrapper iframe {
    max-height: 100% !important;
}

Answer №9

How to Automatically Adjust Height for TinyMCE5

    <style>
      /*Adjusting the height of different elements in TinyMCE editor*/
      .tox-tinymce, .tox-editor-container {
        min-height: 100% !important;
      }

      /*Positioning the sidebar at the bottom*/
      .tox-sidebar-wrap {
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
      }

      /*Positioning the editing area*/
      .tox-edit-area {
        position: absolute;
      }

      /*Positioning the footer/status bar*/
      .tox-tinymce .tox-statusbar {
        position: absolute !important;
        bottom: 0;
        left: 0;
        right: 0;
      }
    </style>

Answer №10

Utilizing CSS calc for this task is my preferred method. Here's the solution that worked effectively:

.mce-tinymce, .mce-edit-area.mce-container, .mce-container-body.mce-stack-layout
{
    height: 100% !important;
}

.mce-edit-area.mce-container {
    height: calc(100% - 88px) !important;
    overflow-y: scroll;
}

It's important to note that the value of 88px accounts for the total height of the headerbar and statusbar.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Jquery animation in Wordpress without any need for scrolling

My Wordpress site features some animations that work flawlessly when the site is scrolled. The code looks like this: jQuery(document).ready(function($){ $(window).scroll( function(){ if(!isMobile) { $('.animate_1').each ...

Is there a way to refresh a Thymeleaf table without reloading the entire page?

Displayed below is both my HTML and JavaScript code, utilizing Thymeleaf to dynamically render table content. The button's functionality changes based on the notified value - if it's 1, the button is disabled with a modified CSS style. When the v ...

Applying CSS Styles to a Single Class Only

I have been using Zurb's Foundation to customize the navbar with my own styles, which has been successful so far. However, I encountered an issue with the responsive behavior of the navbar when the viewing container size changes. The navbar adds a sec ...

Modify the styling of the Checkbox within the script template

I am currently working with a list that contains checkboxes, but they are displaying with the default CSS style. How can I change the CSS style of the checkboxes? Below is the code I am using, and I need to modify the CSS of the checkboxes. <div id ...

Why won't my Bootstrap carousel slide properly?

I am facing an issue with implementing a carousel in my web development course on udemy. Despite applying the necessary controls, the carousel doesn't seem to work as expected. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a hr ...

Can we specify the inherit value for font family on an element to ensure consistent style when the specified font is not available?

Suppose I have a page with the following HTML content: <body style="font-family:Helvetica"> <span style="font-family:Segue">Hello World</span> </body> Would it be considered valid to set the font family of the span to Segue, ...

Concealing an Automatically Updated Section when Devoid of Content -- Ruby on Rails Version 4

I have come across various solutions to this problem, but none of them seem to be effective for my specific project. In my application, the user's previous choices are displayed in multiple divs. Initially, all the divs are empty. As the user progress ...

Exploring the functions of Safari input types: search, reset, and normalize

Is there a proper way to reset the appearance of a search input so that it resembles a text field in Safari? screenshot I'm experiencing an issue with Safari where there is unwanted padding on the left side of the search input that I can't seem ...

Tips for utilizing z-index effectively in conjunction with a sticky header

I'm having trouble getting my footer to display correctly on top of a sticky header. Even though they are both in the same level markup, it just doesn't seem to work as expected. Interestingly, a snippet of code below appears to be working, but ...

The image displayed on the HTML scrset attribute is not the correct one

I'm experiencing an issue with correctly loading the responsive image using scrset. The sizes attribute I am using is: sizes="(max-width: 767px) 95vw, 768px" and for the srcset attribute: srcset="https://cdn.runningshoesguru.com/wp-content/uploads ...

Creating a container that scrolls horizontally

I am working with ngbootstrap and angular, however, I believe the issue at hand is more related to html/css. My goal is to create a container that scrolls horizontally, despite coming across several helpful threads on this topic, I am struggling to impleme ...

The slider causing conflicts with widgets and content positioned below it in an HTML layout

When implementing a slider with a fade effect, there seems to be an issue with the placement of widgets on the homepage. The problem arises from the margin-top setting as when images change in the slider, the widgets clash with the slider. During the trans ...

Setting a fixed time for a preloader is a simple and effective way to

Is there a way to specify a specific duration for the preloader on my website? I find that after the images have preloaded, I am unable to see any animations in the home section. $(window).load(function() { $('#preloader').fadeOut( ...

Tips for dynamically adding a class when a specific section is scrolled to, and removing it when the section is passed

Is there a way to dynamically change the scroll behavior and add or remove a class based on certain conditions? I am new to coding, so any guidance would be greatly appreciated. Thank you! :) $(document).on("scroll", function () { ...

Resize a div within another div using overflow scroll and centering techniques

Currently, I am working on implementing a small feature but am facing difficulties with the scroll functionality. My goal is to zoom in on a specific div by scaling it using CSS: transform: scale(X,Y) The issue I am encountering lies in determining the c ...

Mysterious Chrome glitch causes SVG element to shift down by 2 pixels

I am currently facing an issue with creating image links from an SVG spritesheet that is causing cross-browser problems between Chrome, Safari, and Firefox. Here are some of the anchor tags I am using: <a href="#" id="twitter-logo" class="socialIcon"&g ...

What is the best way to position my NavBar items to the right using the Bootstrap v5.2 framework?

I am working on a project for my course and need some help. My goal is to have the brand stay aligned to the left, while other items align to the right. I have been able to achieve this without a toggler using justify-content-end, but with a toggler, I a ...

Calculating the Vertical Size of a Component within Django Template Design

Within a div element with a fixed width, I have a p element with the following CSS properties: height:100px; overflow:hidden; I am looking to implement a functionality where a MORE button is displayed if the text within the paragraph overflows and is hid ...

Why does my 'click' event listener only work for the first two <li>'s and not the others?

I am new to programming and recently achieved success with my 'click' eventListener. When clicking on the first two li elements within the ul, the class of the div toggles on and off as expected. However, I encountered an issue where clicking on ...

Unable to insert additional lines into diamond shape generated solely with CSS

Is there anyone out there who can assist me in creating this logo using CSS? View the image of the logo here I initially attempted to make a square with width and height, followed by experimenting with pseudo elements. However, I hit a roadblock because ...