M: need a quick css code block to display alternating white/grey backgrounds in a table.
G:
/* Alternating row colors */
table {
border-collapse: collapse;
width: 100%;
}
tr:nth-child(even) {
background-color: #f0f0f0;
}
tr:nth-child(odd) {
background-color: #ffffff;
}If you want the header excluded from the striping:
table {
border-collapse: collapse;
width: 100%;
}
tbody tr:nth-child(even) {
background-color: #f0f0f0;
}
tbody tr:nth-child(odd) {
background-color: #ffffff;
}M: what about for a table of class 'long-table'?
G:
.long-table {
border-collapse: collapse;
width: 100%;
}
.long-table tbody tr:nth-child(even) {
background-color: #f0f0f0;
}
.long-table tbody tr:nth-child(odd) {
background-color: #ffffff;
}M: i'm running a linux php server and it's not showing any change. i have a feeling it's not refreshing the css file (i changed the background color and it didn't budge). can i force this without reopening the browser?
G: Yes. That's almost certainly browser caching, not PHP itself.
Quickest options:
Ctrl+F5Ctrl+Shift+RUsually enough.
If not:
Change:
<link rel="stylesheet" href="style.css">to:
<link rel="stylesheet" href="style.css?v=2">Or better for development in PHP:
<link rel="stylesheet" href="style.css?v=<?php echo time(); ?>">That forces a fresh fetch every page load.
You can also use file modification time instead of
time():
<link rel="stylesheet" href="style.css?v=<?php echo filemtime('style.css'); ?>">That refreshes only when the CSS changes.
Also verify:
F12) → Network tab → disable
cacheA quick sanity test:
body {
background: hotpink !important;
}If that doesn't change, you're definitely editing the wrong file or serving a cached asset.