Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Use a select option to style a different element

1481757086
Lindan
Plus
Sheet Author
A question for the pros among you: many of you use the neat trick to implement tab pages by using radio buttons checked pseudo class to style child elements like: input[value="1"]:checked ~ div.myclass .... This only seems to work with immediate descendents though. is a similar thing possible with select option values? I would like to display background-images on the sheet dependent on a player selection. this would be easy with js but I struggle to do it with css (a internet search indicates this might be impossible) Any ideas?
1481757706
Kryx
Pro
Sheet Author
API Scripter
The trick, at least with roll20, is hidden fields. Example: <input type="hidden" name="attr_rogue_toggle" class="rogue-class-features"> <div class="rogue-class-features-toggle"> I now have some css to hide the adjacent div: .sheet-rogue-class-features:not([value='1']) {   & ~ .sheet-rogue-class-features-toggle {     display: none;   } } I could have a select named "attr_rogue_toggle". When that select change, the hidden field will change. You can then use the css above with text or numbers to change fields that appear later. You can also trigger fields below that as well: .sheet-rogue-class-features:not([value='1']) {   & ~ .sheet-rogue-class-features-toggle {     .sheet-FIELD { display: none; }   } } Or plenty of other CSS options as well. In case you didn't know + is the adjacent sibling while tilde (~) is for any sibling
1481759207
vÍnce
Pro
Sheet Author
I've never "nested" the css like that.  That's cool.  (off to follow a tutorial) Thanks Kryx
1481760076
Kryx
Pro
Sheet Author
API Scripter
Ah, that's sass (scss). Sorry, I forgot to parse it to css to share. I compile it to css during my build.
1481779454

Edited 1481779502
Lithl
Pro
Sheet Author
API Scripter
Vince said: I've never "nested" the css like that.  That's cool.  (off to follow a tutorial) Thanks Kryx Cascading Style Sheets can't actually be nested. Kryx is using Syntactically Awesome Style Sheets, which is actually a scripting language that gets compiled into CSS output. As far as using <select> goes, you can abuse the fact that Roll20 will propagate the value selected to all other inputs with the same name. So, select on option with value=1, let Roll20 set a hidden checkbox/radio with the same name and value=1 to :checked, and go from there.
1481824506

Edited 1481824529
Lindan
Plus
Sheet Author
Thanks guys! You are the best. The value propagation did the trick (even if it feels a bit.... messy....) . I feel I have to take a look at sass sooner or later - it seems really convenient as soon as you get the hang of it. On a (un-)related note: do you know how long it usually takes until a pull request to master is approved?
1481826516
Kryx
Pro
Sheet Author
API Scripter
Typically pulled by roll20 on Monday or Tuesday US time.