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 .
×

Single ":checked" condition for multiple styles. Is it possible?

1536726758

Edited 1536736104
I've been making my own custom character sheet for a while now (without any prior knowledge of html, css or javascript) and there is this small thing that keeps bothering me.  My innate laziness and love for neat things both are protesting the idea of creating multiple html styles that effectively make the same thing. I wonder if it is at all possible to create something like: .sheet-md-npc_options { visibility: collapse; } ... .sheet-is_checked:checked ~ .sheet-md-npc_options { visibility: visible; } and have it fold and unfold multiple div classes one at the time without initializing bunch of styles with only difference being their names? Say something like: <div class="l-mgrid-body"> <!-- TABLE ONE -->     <input class="is_checked" type="checkbox" name="attr_is_checked">     <div class="md-npc_options">         <!-- ROW ONE -->         <!-- ROW TWO -->         <!-- ROW THREE -->     </div> </div> <div class="l-mgrid-body"> <!-- TABLE TWO -->     <input class="is_checked" type="checkbox" name="attr_is_checked">     <div class="md-npc_options">         <!-- ROW ONE -->         <!-- ROW TWO -->         <!-- ROW THREE -->     </div> </div> So far I found out this sort of works: .sheet-l-mgrid-body:hover > .sheet-is_checked:checked ~ .sheet-md-npc_options { visibility: visible; } but it is incredibly wonky, and doesn't actually do want I want, it's just kind of emulating it instead. Is more elegant solution possible at all? Maybe some sort of sheetworker or html/css wizardry?
1536727600
Jakob
Sheet Author
API Scripter
Maybe it's because I've only had one coffee, but I tried to figure out what you actually want to do, and I'm not seeing what the problem is. Do you want one checkbox to control the visibility of several divs? Or do you want several similar checkboxes which control separate divs? I have no idea why the :hover solution would do any of these, so I'm just confused as to what your intent here is.
The last one, yes. I want s imilar checkboxes (all of them sharing the same style) each of them controlling separate divs (same style too). So far no matter which one of the checkboxes I "checked" all  corresponding  divs react  simultaneously. ":hover" actually just hides all "visibility:visible" divs until I hover over them.  So, in summary: multiple checkboxes (sharing style), multiple divs  (sharing other style) , one checkbox checked, only one div reacts. Sorry for troubles, by the way, my communications skills have been out of practice for a while.
1536729992
GiGs
Pro
Sheet Author
API Scripter
Is each checkbox next to the div it controls, or are the checkboxes and divs in separate parts of the character sheet?
Definitely in separate parts of the sheet, each one its own grid-container. Although those grid-containers share the same style too. I guess I'd have to say my intent here is to utilize as little amount of different styles as possible. 
1536743982
Finderski
Pro
Sheet Author
Compendium Curator
Make sure the checkboxes all have different names. They can share a style, but if they have the same name, checking one will check them all. You can also use the + rather than the ~.  The + means it has to be next to div, whereas the ~ means it needs to be at the same level <checkbox> <div 1>     <div 1a></div 1a>     <div 1b</div 1b> </div 1> <div 2>     <div 2a></div 2a>     <div 2b></div 2b> </div 2> So, if you had the check with a + it would only impact div 1. If you used the ~ it would hit both divs 1 and 2 (assuming they both met the criteria)
That works! Such an obvious thing, now I feel stupid. Thank you kindly.
1536748739
Jakob
Sheet Author
API Scripter
You probably know this, but make sure that different checkboxes have different name attributes, otherwise they will not be independent after all.