html - Coloring rows in a table with n colors -
I know that I weird and even I can use the colors of the optional rows in a table, however, I want to be able to paint every third row, so colorful red-green-blue-red-green-blue < / Em> looks like. Besides, I want to make that general and use n colors in style in every n: th line. At the moment, I generate the table dynamically and each recurrence I, each td like modulo0 , modulo1 etc. > Put a class name on the tag. What is a better way? A more automated, this is it. you HTML CSS More commonly, to change the number of places of Note that only comes in IE9. If support for IE8 is required, then an alternative solution is required, such as manual classes or JavaScript. : nth-child selector
3n With each other, each other can be connected to start each other, second or third.
& lt; Table & gt; & Lt; TR & gt; & Lt; TD & gt; R & lt; / TD & gt; & Lt; / TR & gt; & Lt; TR & gt; & Lt; TD & gt; G & lt; / TD & gt; & Lt; / TR & gt; & Lt; TR & gt; & Lt; TD & gt; B & lt; / TD & gt; & Lt; / TR & gt; & Lt; TR & gt; & Lt; TD & gt; R & lt; / TD & gt; & Lt; / TR & gt; & Lt; TR & gt; & Lt; TD & gt; G & lt; / TD & gt; & Lt; / TR & gt; & Lt; TR & gt; & Lt; TD & gt; B & lt; / TD & gt; & Lt; / TR & gt; & Lt; / Table & gt;
tr: nth-child (3n + 1) td {background-color: red; } Tr: nth-child (3n + 2) td {background-color: green; } Tr: nth-child (3n) td {background-color: blue; }
Generally
3 in which to change the color.
tr: nth-child (2n) td {} / * every second row * / tr: nth-child (4n) td {} / * every fourth row * / tr: nth- Child (10n) td {} / * every tenth row * /
support
Comments
Post a Comment