I am currently using CSS to create tabs with radio buttons. However, I am struggling to figure out how to select the corresponding <label>
for the radio button. To keep the labels separate from the content and display them as tabs, I have structured them as follows:
<div class="tab-labels">
<label for="tab-1">Tab 1</label>
<label for="tab-2">Tab 2</label>
<label for="tab-3">Tab 3</label>
</div>
The content panes are positioned below. The radio input button is placed inside the content div so that it can be selected when the label is clicked. Unfortunately, I am unable to achieve this in reverse order:
<div class="content-container">
<div class="tab details">
<input id="tab-1" type="radio" name="radio-set" class="tab-selector" checked="checked"/>
<div class="content">
<p>Some content 1</p>
</div>
</div>
<div class="tab details">
<input id="tab-2" type="radio" name="radio-set" class="tab-selector"/>
<div class="content">
<p>Some content 2</p>
</div>
</div>
<div class="tab details">
<input id="tab-3" type="radio" name="radio-set" class="tab-selector"/>
<div class="content">
<p>Some content 3</p>
</div>
</div>
</div>
My main goal and question regarding this issue is: How can I change the background color of the label when the radio input is clicked based on this structure?
If you would like to experiment with this setup live, I have provided a fiddle link: http://jsfiddle.net/mjohnsonco/6KeTR/