I need to apply some styles to a div for printing. I can use a media query @media print {}
to accomplish this easily. But I also sometimes need to apply the same styles on the browser itself, before the print dialog is opened. I'm trying to do this by adding a div .print-view
to the page. But can't find a way to do it without code duplication.
I've tried this, but it's invalid css:
.print-view, @media print {
.grey-background {
background-color: white;
}
}
I've also tried this (scss), but it causes an error @extend may only be used within style rules.
.print-view {
.grey-background {
background-color: white;
}
}
@media print {
@extend .print-view;
}
Is there some other way for me to accomplish this?
Edit: changed sample code to more accurately reflect what I'm trying to do