Skip to content

Commit e59f9f4

Browse files
authored
Merge pull request ChartsCSS#7 from ramiy/main
Colors: use pseudo classes
2 parents fc6858a + 3e2bad7 commit e59f9f4

File tree

1 file changed

+121
-21
lines changed

1 file changed

+121
-21
lines changed

src/components/colors.md

Lines changed: 121 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ To change specific element color, we need to apply the `--color` variable on a s
187187
</template>
188188
</code-example>
189189

190-
This method can be also applied on all the `<td>` elements.
190+
This method can be also applied on all the `<td>` elements one by one.
191191

192192
```html{3,7,11}
193193
<tr>
@@ -283,7 +283,7 @@ This method can be also applied on all the `<td>` elements.
283283
</template>
284284
</code-example>
285285

286-
**Note:** With small data tables it's an acceptable method but with large tables it's a not a recommended practice. Keep reading to learn how to [change global colors](#change-global-colors).
286+
**Note:** With small data tables it's an acceptable method to override colors for each `<td>` element but with large tables it's a not a recommended practice. Keep reading to learn how to [change global colors](#change-global-colors).
287287

288288
## Change Global Colors
289289

@@ -325,7 +325,7 @@ It works well with single datasets:
325325
}
326326
</template>
327327
<template v-slot:html-code>
328-
<table class="charts-css column show-labels hide-data data-spacing-2" id="colors-example-4">
328+
<table class="charts-css column show-labels hide-data data-spacing-2 show-primary-axis" id="colors-example-4">
329329

330330
<caption> Colors Example #4 </caption>
331331

@@ -404,7 +404,7 @@ And with multiple datasets:
404404
}
405405
</template>
406406
<template v-slot:html-code>
407-
<table class="charts-css column multiple show-labels hide-data data-spacing-10 datasets-spacing-1 show-data-axes" id="colors-example-5">
407+
<table class="charts-css column multiple show-labels hide-data data-spacing-10 datasets-spacing-1 show-primary-axis show-data-axes" id="colors-example-5">
408408

409409
<caption> Colors Example #5 </caption>
410410

@@ -698,6 +698,106 @@ You can set gradients on any CSS variables mentioned above.
698698
</template>
699699
</code-example>
700700

701+
## Use Pseudo Classes
702+
703+
You can use CSS pseudo-classes to target the elements you want to color.
704+
705+
```css
706+
#my-chart tr {
707+
--color: #fdc;
708+
}
709+
#my-chart tr:nth-child(n+8):not(:last-child) {
710+
--color: #f84;
711+
}
712+
#my-chart tr:last-child {
713+
--color: repeating-linear-gradient(135deg, #fdc 0px, #fdc 6px, #f84 6px, #f84 12px);
714+
}
715+
```
716+
717+
<code-example code-example-id="colors-example-9">
718+
<template v-slot:css-code>
719+
#colors-example-9 {
720+
height: 200px;
721+
max-width: 800px;
722+
margin: 0 auto;
723+
}
724+
#colors-example-9 tr {
725+
--color: #fdc;
726+
}
727+
#colors-example-9 tr:nth-child(n+8):not(:last-child) {
728+
--color: #f84;
729+
}
730+
#colors-example-9 tr:last-child {
731+
--color: repeating-linear-gradient(135deg, #fdc 0px, #fdc 6px, #f84 6px, #f84 12px);
732+
}
733+
</template>
734+
<template v-slot:html-code>
735+
<table class="charts-css column show-labels hide-data data-spacing-5" id="colors-example-9">
736+
737+
<caption> Colors Example #9 </caption>
738+
739+
<thead>
740+
<tr>
741+
<th scope="col"> Month </th>
742+
<th scope="col"> Progress </th>
743+
</tr>
744+
</thead>
745+
746+
<tbody>
747+
<tr>
748+
<th scope="row"> Jan </th>
749+
<td style="--size: 0.48;"> <span class="data"> 48 </span> </td>
750+
</tr>
751+
<tr>
752+
<th scope="row"> Feb </th>
753+
<td style="--size: 0.40;"> <span class="data"> 40 </span> </td>
754+
</tr>
755+
<tr>
756+
<th scope="row"> Mar </th>
757+
<td style="--size: 0.36;"> <span class="data"> 36 </span> </td>
758+
</tr>
759+
<tr>
760+
<th scope="row"> Apr </th>
761+
<td style="--size: 0.38;"> <span class="data"> 38 </span> </td>
762+
</tr>
763+
<tr>
764+
<th scope="row"> May </th>
765+
<td style="--size: 0.48;"> <span class="data"> 48 </span> </td>
766+
</tr>
767+
<tr>
768+
<th scope="row"> Jun </th>
769+
<td style="--size: 0.60;"> <span class="data"> 60 </span> </td>
770+
</tr>
771+
<tr>
772+
<th scope="row"> Jul </th>
773+
<td style="--size: 0.78;"> <span class="data"> 78 </span> </td>
774+
</tr>
775+
<tr>
776+
<th scope="row"> Aug </th>
777+
<td style="--size: 0.88;"> <span class="data"> 88 </span> </td>
778+
</tr>
779+
<tr>
780+
<th scope="row"> Sep </th>
781+
<td style="--size: 0.96;"> <span class="data"> 96 </span> </td>
782+
</tr>
783+
<tr>
784+
<th scope="row"> Oct </th>
785+
<td style="--size: 1.00;"> <span class="data"> 100 </span> </td>
786+
</tr>
787+
<tr>
788+
<th scope="row"> Nov </th>
789+
<td style="--size: 0.97;"> <span class="data"> 97 </span> </td>
790+
</tr>
791+
<tr>
792+
<th scope="row"> Dec </th>
793+
<td style="--size: 0.84;"> <span class="data"> 84 </span> </td>
794+
</tr>
795+
</tbody>
796+
797+
</table>
798+
</template>
799+
</code-example>
800+
701801
## Use Patterns
702802

703803
You can even use custom CSS patterns.
@@ -720,9 +820,9 @@ You can even use custom CSS patterns.
720820

721821
Repeating gradients will do the trick.
722822

723-
<code-example code-example-id="colors-example-9">
823+
<code-example code-example-id="colors-example-10">
724824
<template v-slot:css-code>
725-
#colors-example-9 {
825+
#colors-example-10 {
726826
height: 200px;
727827
max-width: 800px;
728828
margin: 0 auto;
@@ -740,9 +840,9 @@ Repeating gradients will do the trick.
740840
}
741841
</template>
742842
<template v-slot:html-code>
743-
<table class="charts-css column show-labels hide-data data-spacing-5" id="colors-example-9">
843+
<table class="charts-css column show-labels hide-data data-spacing-5" id="colors-example-10">
744844

745-
<caption> Colors Example #9 </caption>
845+
<caption> Colors Example #10 </caption>
746846

747847
<thead>
748848
<tr>
@@ -830,25 +930,25 @@ Three repeating colors in a single datasets table:
830930

831931
<code-example code-example-id="colors-example-10">
832932
<template v-slot:css-code>
833-
#colors-example-10 {
933+
#colors-example-11 {
834934
height: 200px;
835935
max-width: 800px;
836936
margin: 0 auto;
837937
}
838-
#colors-example-10:not(.multiple) tbody tr:nth-of-type(3n + 1) td {
938+
#colors-example-11:not(.multiple) tbody tr:nth-of-type(3n + 1) td {
839939
background-color: #f06464;
840940
}
841-
#colors-example-10:not(.multiple) tbody tr:nth-of-type(3n + 2) td {
941+
#colors-example-11:not(.multiple) tbody tr:nth-of-type(3n + 2) td {
842942
background-color: #8cdc78;
843943
}
844-
#colors-example-10:not(.multiple) tbody tr:nth-of-type(3n + 3) td {
944+
#colors-example-11:not(.multiple) tbody tr:nth-of-type(3n + 3) td {
845945
background-color: #82beff;
846946
}
847947
</template>
848948
<template v-slot:html-code>
849-
<table class="charts-css column show-labels hide-data" id="colors-example-10">
949+
<table class="charts-css column show-labels hide-data" id="colors-example-11">
850950

851-
<caption> Colors Example #10 </caption>
951+
<caption> Colors Example #11 </caption>
852952

853953
<thead>
854954
<tr>
@@ -914,27 +1014,27 @@ Three repeating colors in a single datasets table:
9141014

9151015
Three repeating colors in a multiple datasets table:
9161016

917-
<code-example code-example-id="colors-example-11">
1017+
<code-example code-example-id="colors-example-12">
9181018
<template v-slot:css-code>
919-
#colors-example-11 {
1019+
#colors-example-12 {
9201020
height: 200px;
9211021
max-width: 800px;
9221022
margin: 0 auto;
9231023
}
924-
#colors-example-11.charts-css.multiple tbody tr td:nth-of-type(3n + 1) {
1024+
#colors-example-12.charts-css.multiple tbody tr td:nth-of-type(3n + 1) {
9251025
background-color: #f06464;
9261026
}
927-
#colors-example-11.charts-css.multiple tbody tr td:nth-of-type(3n + 2) {
1027+
#colors-example-12.charts-css.multiple tbody tr td:nth-of-type(3n + 2) {
9281028
background-color: #8cdc78;
9291029
}
930-
#colors-example-11.charts-css.multiple tbody tr td:nth-of-type(3n + 3) {
1030+
#colors-example-12.charts-css.multiple tbody tr td:nth-of-type(3n + 3) {
9311031
background-color: #82beff;
9321032
}
9331033
</template>
9341034
<template v-slot:html-code>
935-
<table class="charts-css column multiple show-labels hide-data data-spacing-10 show-data-axes" id="colors-example-11">
1035+
<table class="charts-css column multiple show-labels hide-data data-spacing-10 show-data-axes" id="colors-example-12">
9361036

937-
<caption> Colors Example #11 </caption>
1037+
<caption> Colors Example #12 </caption>
9381038

9391039
<thead>
9401040
<tr>

0 commit comments

Comments
 (0)