How do I conditionally apply a @media print
css ruleset ONLY when a certain div is present on the page.
I have the following css which helps when printing #mytargetdiv
:
@media print {
.inside-article > :not(#mytargetdiv), .inside-navigation, .site-footer {
display: none;
}
}
It works great, except that some pages have #mytargetdiv
and some do not contain a div with that id. If a div with the id #mytargetdiv
is NOT present on the given page, then I do not want to apply this @media print
rule.
How do I exclude this @media print
css rule on pages that do not contain #mytargetdiv
.