HTML [Solved] CSS help?

TCMS

Quote my posts if you want an answer
Donor
Former Staff
Aug 5, 2016
5,797
30,913
so a bit of a weird question, but to all you css freaks, is there a way to get several fields into 1, as a way to act like an OR operator, so they'll affect the same field afterwards?

For example you have:

CSS:
a.Field1> div.Class3,
a.Field2> div.Class3,
a.Field4> div.Class3,
a.Field5> div.Class3 {
  background-color: #fff;
}
Is there a way to bundle all those a.Field together and have them affect the div.Class3 so the code: "> div.Class3" isn't repeated each time another a.Field is added?

Note: Not all a.FieldX (where x = number) are supposed to be affected by this code so please don't mentioned using *
 

scrumbles

Well-Known Member
Jan 12, 2019
1,069
1,096
This rule is applied on all links whose "class" attribute starts by "Field" and doesn't end by "3":
Code:
a[class^="Field"]:not([class$="3"]) > div.Class3 {background-color: #fff; }
If there is a "a.Field6", you can discard it as well:
Code:
a[class^="Field"]:not([class$="3"]):not([class$="6"]) > div.Class3 {background-color: #fff; }
I can think of more solutions, but without knowing the HTML code, I don't know if they are better than this one.
 

TCMS

Quote my posts if you want an answer
Donor
Former Staff
Aug 5, 2016
5,797
30,913
This rule is applied on all links whose "class" attribute starts by "Field" and doesn't end by "3":
Code:
a[class^="Field"]:not([class$="3"]) > div.Class3 {background-color: #fff; }
If there is a "a.Field6", you can discard it as well:
Code:
a[class^="Field"]:not([class$="3"]):not([class$="6"]) > div.Class3 {background-color: #fff; }
I can think of more solutions, but without knowing the HTML code, I don't know if they are better than this one.
See the problem is that the majority of Fields are not meant to be captured by this code.

The true adaptation of this code is for Latest Updates. I was tired of downloading games I've played and didn't enjoy so my way to counter this was to make sure that games like those would appear as red. So here's a pic of the code in effect:

Whilst the list is quite long here's a small example of the code:
CSS:
a[href*="/threads/115/"] > div.resource-tile_body,
a[href*="/threads/1282/"] > div.resource-tile_body,
a[href*="/threads/8432/"] > div.resource-tile_body,
a[href*="/threads/12143/"] > div.resource-tile_body,
a[href*="/threads/27293/"] > div.resource-tile_body,
a[href*="/threads/28238/"] > div.resource-tile_body,
a[href*="/threads/38582/"] > div.resource-tile_body,
a[href*="/threads/38874/"] > div.resource-tile_body,
a[href*="/threads/38970/"] > div.resource-tile_body,
a[href*="/threads/45841/"] > div.resource-tile_body,
a[href*="/threads/45870/"] > div.resource-tile_body,
a[href*="/threads/45898/"] > div.resource-tile_body
{
    background-color: #ff6060 !important;
}
The problem is that the list keeps increasing and all of this repetitive code... just looks ugly as crap tbh. So was hoping for a way to reduce it. If it's not possible then... welp, just gotta deal with it.
 

scrumbles

Well-Known Member
Jan 12, 2019
1,069
1,096
There is an experimental feature:
Code:
:is(
	a[href$="/115/"],
	a[href$="/1282/"],
	a[href$="/8432/"],
	...
) > div.Class3 {background-color: #ff6060 !important; }
On Chrome it works if you visit chrome://flags and and set "Experimental Web Platform Features" to Enabled; or just replace "is" with ":-webkit-any". On Firefox, replace ":is" with ":-moz-any".
Of course I'm talking of the latest releases (read more ).

This is what it looks closer to a for loop, which is what you need, I guess. Alternatively, you can create your custom rules through Tampermonkey or a local script (cmd.exe, Powershell, .sh) and iterate on the ID list.
 
Last edited:
  • Like
Reactions: TCMS

TCMS

Quote my posts if you want an answer
Donor
Former Staff
Aug 5, 2016
5,797
30,913
There is an experimental feature:
Code:
:is(
    a[href$="/115/"],
    a[href$="/1282/"],
    a[href$="/8432/"],
    ...
) > div.Class3 {background-color: #ff6060 !important; }
On Chrome it works if you visit chrome://flags and and set "Experimental Web Platform Features" to Enabled; or just replace "is" with ":-webkit-any". On Firefox, replace ":is" with ":-moz-any".
Of course I'm talking of the latest releases (read more ).

This is what it looks closer to a for loop, which is what you need, I guess. Alternatively, you can create your custom rules through Tampermonkey or a local script (cmd.exe, Powershell, .sh) and iterate on the ID list.
Didn't even need to active that flags :-webkit-any( ) worked o_O thanks man :whistle:
 
  • Like
Reactions: scrumbles