I have a CSS table like this:
(this is a reliable simplification of my system)
<
-
Pure CSS Answer (CSS3)
There are some careful considerations to take into account (see below), but there does appear to be a way to do this in pure css (note that fiddle uses the fake div table per this post, but it could be done with real html tables) using a linear-gradient with color stops (technique found here) on the table background. The key to make it flexible with font-size changes (or zooming) is to set the height portion of the background-size to twice the line-height set for the rows.
Considerations:
line-height and font-size for row should be explicitly set with em units (except see note #5 below).
- If
padding is set on the table (not recommended) then some type of adjustment to either background-position or background-clip will likely need to be done to accommodate the padding.
- If top or bottom
padding or margin is set on the row then it should be in em units and added to the line-height value before calculating the doubled linear-gradient height.
- This technique will change color of background within a row if that row has multiple lines in it (see the last table in my example fiddle).
- If some other fixed height element were in the rows (images set to 20px high), then the
row height and linear-gradient height could be set based off pixel values.
I have not taken the time to play around with #2 and #3 above to figure out for sure the exact adjustments needed, but theoretically it should be possible to accommodate those things if necessary.
讨论(0)