I am working on solving a conundrum, and I have it mostly figured out except for one big part:
Imagine if you will 5 divs. A Header and 4 Sections (a - d).
Each section has an open/close toggle I did using the CSS Checkbox Hack to toggle the value of open/close. When open, a section displays content inside of it and the button toggles to 'close' Clicking that hides the content and toggles the button back to 'open'. All that works just fine.
As part of the requirements: the Header should be constantly displaying which sections are open, in a grammatically correct form:
"all sections are closed"
"section A is open"
"sections A and C are open" <-- the plural is important here.
I am a javascript guy mostly and this would be a trivial problem in javascript. Problem is? Has to be pure CSS. Why? Because that's the requirement. I suspect I am actually instead being tested on whether or not I can find the resources necessary to solve the problem. I say this because it's a javascript development position - so odd they would test me on pure CSS, AND it's a 100% remote position. When I used to work remote, 80% of the job was googling or SO, so here I am. ;)
I'm assuming that the solution involves abusing the content: property along with a css counter or even multiple ones, but so far, I am at a loss as to how one might do it.
Any markup is allowed, and any CSS, but NO javascript. Also has to be cross-browser compatible, but I will be satisfied with it working on ONE to start with.
Can someone point me in the right direction?
TIA.
Edit: Code of what I've got so far:
input[type='checkbox'] {
visibility: hidden;
}
label:after {
color: blue;
text-decoration: underline;
display: inline;
position: absolute;
right: 10px;
content: 'open';
}
#sectionA:checked ~ label:after {
content: 'close';
}
.section {
border: 1px solid black;
border-radius: 4px;
margin: 1% auto;
position: relative;
line-height: 35px;
padding-left: 5px;
width: 100%;
}
.header {
background-color: #ddd;
}
.sectionName {
color: #ffa500;
font-style: italic;
display: inline;
}
.sectionContent {
max-height: 0;
display: none;
transition: all .4s;
}
#sectionA:checked + .sectionContent {
max-height: 30px;
display: block;
}
.clearfix:after {
visibility: hidden;
display: block;
font-size: 0;
content: " ";
clear: both;
height: 0;
}
.clearfix {
display: inline-block;
}
#siblings {
color: #333;
}
#siblings,
h2 ~ div {
color: red;
}
<div class="section header">
<span id="headerMessage">all sections are closed</span>
</div>
<div class="section closed clearfix">
section <span class="sectionName">a</span>
<label for="sectionA" id="labelA"></label>
<input type=checkbox id="sectionA" />
<div class="sectionContent">section <span class="sectionName">a</span> content</div>
</div>
<div class="section closed clearfix">
section <span class="sectionName">b</span>
<label for="sectionB"></label>
<input type=checkbox id="sectionB" />
<div class="sectionContent">section <span class="sectionName">b</span> content</div>
</div>
<div class="section closed">
section <span class="sectionName">c</span>
</div>
<div class="section closed">
section <span class="sectionName">d</span>
</div>
I haven't added the classes for sections b-d, hence them not working yet, but they will act the same as section a.