I initially had some tabs created with radio buttons and labels which are linked to corresponding divs using their IDs and was working fine. But the problem is I am now creating the radio button tabs and their corresponding divs dynamically and wish to still allow my css to know which one should be open when a radio button is checked.
My CSS:
#tab-1:checked~.content #content-1,
#tab-2:checked~.content #content-2,
#tab-3:checked~.content #content-3,
#tab-4:checked~.content #content-4,
#tab-4:checked~.content #content-5 {
display: block;
}
With the above initially, when the radio button with id of tab-1
is checked, the div with id of content-1
is displayed but right now this will no longer work for me as I am now creating the radio buttons dynamically using incoming IDs from my DB like: #tab-100, #tab-101, #tab-102
and the divs as well #content-100, #content-101, #content-102
. I need my CSS to be dynamic as well so when #tab-100
is checked, it automatically displays #content-100
. I am aware I can do this with javascript but I want to believe that there is a way to do it with CSS.