Is there a way to conditionally apply a @media print
css ruleset only when a specific div is present on the page?
For example, I have the following css to assist in printing #mytargetdiv
:
@media print {
.inside-article > :not(#mytargetdiv), .inside-navigation, .site-footer {
display: none;
}
}
While this works well for pages with #mytargetdiv
, not all pages have a div with that id. How can I ensure that this @media print
rule is only applied when #mytargetdiv
is present on the page?
Any suggestions on excluding this @media print
css rule for pages that do not include #mytargetdiv
?