Reputation:
I have seen some answers to this but I think I am actually having a CSS issue.
Here is a sample fragment of my HTML:
<id=container> children <id="modal">children</modal></container>
If I pop open the modal there is a print button. When I click it I use jQuery to apply a .noprint
to #container
and .print
to #modal
. But the .print
to modal is disregarded, no matter what selector I apply I can't get the modal content to appear. What's worse, I cant use firebug, it is not showing me what print styles are being applied. I have tried
#container #modal.print {display: block; }
etc...
thanks!
Upvotes: 4
Views: 32512
Reputation: 6749
There is another way to print modal window contents. Add this function to modal window
I have tried this and it works. You only need to play around with stylesheets.
Upvotes: 4
Reputation: 103387
From the sound of it, your modal element is inside of the container. I'm guessing you have markup like this.
<div id="container">
<span>children</span>
<p>more children>
<div id="modal">
Modal text!
</div>
</div>
And CSS like this...
.noprint { display: none;}
.print {display: block;}
Which you use JavaScript to apply, like this:
<div id="container" class="noprint">
<span>children</span>
<p>more children>
<div id="modal" class="print">
Modal text!
</div>
</div>
In these examples, the #modal
element is inside of a hidden container. The CSS spec dictates that if a parent element is hidden, all children will be hidden also, even if they are set to display: block
(or any other valid display
value) or are absolutely positioned.
What you should do if you want to hide everything on the page except for your modal window is get your markup to be structured something like this:
<div id="modal">
Modal Text!
</div>
<div id="container">
<span>children</span>
<p>more children>
<div id="modal">
Modal text!
</div>
</div>
If you have no control over where the modal element is rendered, you can use jQuery to re-position the modal element. Keep in mind that this may impact your modal window's layout:
// Moves the element outside of the hidden container
$("#container").before($("#modal"));
Upvotes: 10