Printing MooTools Accordion Items

By  on  
MooTools Accordion

Sometimes we're presented with unforeseen problems when it comes to our JavaScript effects. In this case, I'm talking about printing jQuery and MooTools accordions. Each "closed" accordion content element has its height set to 0 which means it will be hidden when the user tries to print the page. Luckily MooTools Core Developer Thomas Aylott provides a simple fix.

The CSS Fix

@media print {
	.element { height:auto !important; }
}

That's it -- no joke. Setting a print-specific height of auto with the ever-useful !important declaration fixes everything.

Big ups to @subtlegradient for the solution. Another reason I'm so happy to be surrounded by clever developers.

Recent Features

  • By
    Responsive Images: The Ultimate Guide

    Chances are that any Web designers using our Ghostlab browser testing app, which allows seamless testing across all devices simultaneously, will have worked with responsive design in some shape or form. And as today's websites and devices become ever more varied, a plethora of responsive images...

  • By
    39 Shirts – Leaving Mozilla

    In 2001 I had just graduated from a small town high school and headed off to a small town college. I found myself in the quaint computer lab where the substandard computers featured two browsers: Internet Explorer and Mozilla. It was this lab where I fell...

Incredible Demos

  • By
    HTML5 Placeholder Styling with CSS

    Last week I showed you how you could style selected text with CSS. I've searched for more interesting CSS style properties and found another: INPUT placeholder styling. Let me show you how to style placeholder text within INPUTelements with some unique CSS code. The CSS Firefox...

  • By
    Element Position Swapping Using MooTools 1.2

    We all know that MooTools 1.2 can do some pretty awesome animations. What if we want to quickly make two element swap positions without a lot of fuss? Now you can by implementing a MooTools swap() method. MooTools 1.2 Implementation MooTools 1.2 Usage To call the swap...

Discussion

  1. wow… that is really enlightening. thanks for sharing

  2. Anton Samper

    I tell you what, i don’t have a use for this right now, but it’s one of those things that will undoubtably drive me crazy in the future. Very nice dude, i’ll keep it mind.

  3. Thanks for posting about print stylesheets – they are something which are all too often overlooked, but a very important part of web development in my opinion.

  4. So simple… Thanks for the tips.

  5. Gui
    @media print {
    .element { display:inline !important; }
    }
    

    should also work

  6. David

    I’ve recently run up against this problem. The script provided works fine, but as far as I can tell, you can’t use the opacity effect with the accordion.

    I’ve added:

    body div.element {
    height:auto !important;
    display:inline !important; 
    opacity:1 !important;
    filter:alpha(opacity=1); !important;  }
    

    To my print css, but it doesn’t fix the problem. If anybody knows of a solution, then I’m certainly listening. :)

  7. john

    (Accordion mootools)…can be linked to any part of which is not active? How? I thank you in advance

  8. Francisco

    @David: The same problem. Height:auto works but no text is show.

  9. Thanks for this was bugging me for ages. The text was disappearing for me too but the “display:inline !important” seems to fix it (Thanks to Gui).

    Saf

  10. Michelle

    Neither of the fixes presented here have worked for me. Only the section headline shows up on print.

  11. If anyone still comes across this problem: only the following code helped me (jQuery Accordion):

    .ce_accordion { display: block !important; height: auto !important; }

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!