Skip to the content...

Welcome to the David Walsh Blog. I'm a MooTools, Dojo, jQuery, CSS, and PHP Web Developer located in Madison, Wisconsin, United States. Please contact me if I can make your experience on my website better.

Printing MooTools Accordion Items

11 Responses »
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.

Discussion

  1. January 27, 2010 @ 10:09 am

    wow… that is really enlightening. thanks for sharing

  2. anton samper
    January 28, 2010 @ 3:58 am

    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. January 28, 2010 @ 8:22 am

    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. January 28, 2010 @ 8:25 am

    So simple… Thanks for the tips.

  5. gui
    January 29, 2010 @ 5:29 pm

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

    should also work

  6. david
    February 7, 2010 @ 5:40 am

    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
    May 27, 2010 @ 4:55 am

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

  8. francisco
    May 27, 2010 @ 11:17 am

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

Be Heard!

Share your thoughts with fellow developers of all skill levels! I want to hear from you!

Name*:
Email*:
Website:  
Wrap your code with <code> tags, f00!