I'm having trouble with my CSS for print styles. I have the following media query set up, but the `tr` inside my `#tblOutput` isn't getting styled when I print. The table itself looks fine, but the rows don't seem to apply any of the row formatting. If I remove the media query altogether, everything works perfectly. Can someone help me figure out what I'm missing?
2 Answers
You're onto something! The browser does recognize nested selectors, but not within a media query. That's why your `tr:nth-child(even)` styles are being ignored. You definitely want to keep your CSS rules flat rather than nested for them to apply properly. So separating them like the other user suggested will help resolve the issue. Also, remember to fix that margin using inches instead of quotes!
It looks like you may have nested rules in your CSS, which plain CSS doesn't support. Instead of nesting `#tblOutput` and `tr:nth-child(even)` like SCSS, you need to separate them. Each selector in regular CSS should be its own rule. Here's how you should structure it:
```css
@media print {
* {
margin: 0;
padding: 0;
}
div:not(#menucontent) {
display: none;
}
div#menucontent {
position: relative;
left: 0;
top: 0;
margin: .5in .5in;
width: 100%;
}
#tblOutput {
width: 100%;
border: 1px solid red;
}
#tblOutput tr:nth-child(even) {
border: 1px solid green;
background-color: #FFFF00 !important;
}
td {
padding: .25rem;
}
.no-print {
display: none;
}
}
```
This should solve the issue and make sure your row styles show up when printing! And also, just a quick note: make sure to use `in` for inches in your margin declarations instead of `"` which isn’t valid.

Related Questions
How to Build a Custom GPT Journalist That Posts Directly to WordPress
Cloudflare Origin SSL Certificate Setup Guide
How To Effectively Monetize A Site With Ads