I know how to use the tabs macro on Tiddlywiki, but there are a few instances where I don't want an entire tiddler dedicated for a handful of lines.
I'm not great with coding, so I've been mainly stumbling through different CSS tabs examples I find through google searches. The one that I had the most success (which is down below) is something I've stumbled onto from this site.
Any help at all would be appreciated. Thanks.
The HTML part.
<div class="tabs">
<input type="radio" id="tab1" name="tabs" checked>
<input type="radio" id="tab2" name="tabs">
<input type="radio" id="tab3" name="tabs">
<div class="tab-labels">
<label for="tab1">Tab 1</label>
<label for="tab2">Tab 2</label>
<label for="tab3">Tab 3</label>
</div>
<div id="content1" class="tab-content">
<h2>Tab 1</h2>
<p>This is the content for Tab 1.</p>
</div>
<div id="content2" class="tab-content">
<h2>Tab 2</h2>
<p>This is the content for Tab 2.</p>
</div>
<div id="content3" class="tab-content">
<h2>Tab 3</h2>
<p>This is the content for Tab 3.</p>
</div>
</div>
And the CSS part.
.tabs {
display: block;
flex-direction: column;
padding-right: 1em;
}
.tabs .tab-labels {
display: flex;
gap: 3px;
}
.tabs input[type="radio"] {
display: none;
}
.tabs label {
font-size: 15px;
padding: 0.25em;
background: #353235;
border-left: 10px;
cursor: pointer;
}
.tabs input[type="radio"]:checked + label {
background-color: #4a4a4a;
border-bottom: 2px solid blue;
}
.tab-content {
padding-left: 1em;
border: 5px solid gray;
display: none;
background: #353935;
}
/* Show tab content when corresponding radio button is checked */
#tab1:checked ~ #content1,
#tab2:checked ~ #content2,
#tab3:checked ~ #content3 {
display: block;
}
Everything that I've found/looked up suggests that something relating to:
input[type="radio"]:checked + .tab-label {
}
Is what makes the selected tab highlighted work, but nothing I've tried makes the code I have get the highlight on Tiddlywiki. I've tried using different CSS tabs examples from across the net, but nothing really works out for me.
My coding knowledge is practically nil, and what I'm using here is probably missing some crucial part, but that's because I'm mainly focused on the output. I just find some coding examples, compare and contrast them, sometimes try and tweak some variables around to either modest success or expected failure.
I know how to use the tabs macro on Tiddlywiki, but there are a few instances where I don't want an entire tiddler dedicated for a handful of lines.
I'm not great with coding, so I've been mainly stumbling through different CSS tabs examples I find through google searches. The one that I had the most success (which is down below) is something I've stumbled onto from this site.
Any help at all would be appreciated. Thanks.
The HTML part.
<div class="tabs">
<input type="radio" id="tab1" name="tabs" checked>
<input type="radio" id="tab2" name="tabs">
<input type="radio" id="tab3" name="tabs">
<div class="tab-labels">
<label for="tab1">Tab 1</label>
<label for="tab2">Tab 2</label>
<label for="tab3">Tab 3</label>
</div>
<div id="content1" class="tab-content">
<h2>Tab 1</h2>
<p>This is the content for Tab 1.</p>
</div>
<div id="content2" class="tab-content">
<h2>Tab 2</h2>
<p>This is the content for Tab 2.</p>
</div>
<div id="content3" class="tab-content">
<h2>Tab 3</h2>
<p>This is the content for Tab 3.</p>
</div>
</div>
And the CSS part.
.tabs {
display: block;
flex-direction: column;
padding-right: 1em;
}
.tabs .tab-labels {
display: flex;
gap: 3px;
}
.tabs input[type="radio"] {
display: none;
}
.tabs label {
font-size: 15px;
padding: 0.25em;
background: #353235;
border-left: 10px;
cursor: pointer;
}
.tabs input[type="radio"]:checked + label {
background-color: #4a4a4a;
border-bottom: 2px solid blue;
}
.tab-content {
padding-left: 1em;
border: 5px solid gray;
display: none;
background: #353935;
}
/* Show tab content when corresponding radio button is checked */
#tab1:checked ~ #content1,
#tab2:checked ~ #content2,
#tab3:checked ~ #content3 {
display: block;
}
Everything that I've found/looked up suggests that something relating to:
input[type="radio"]:checked + .tab-label {
}
Is what makes the selected tab highlighted work, but nothing I've tried makes the code I have get the highlight on Tiddlywiki. I've tried using different CSS tabs examples from across the net, but nothing really works out for me.
My coding knowledge is practically nil, and what I'm using here is probably missing some crucial part, but that's because I'm mainly focused on the output. I just find some coding examples, compare and contrast them, sometimes try and tweak some variables around to either modest success or expected failure.
Share Improve this question asked 2 days ago FrustratedBallFrustratedBall 31 bronze badge New contributor FrustratedBall is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.1 Answer
Reset to default 0
input[type="radio"]:checked + .tab-label
+
is the next sibling combinator - but your labels aren't the next sibling of their respective checkbox. You need to handle this the same way, as you did with the tab content elements - using the subsequent-sibling combinator, ~
. And the labels are not the siblings of the checkboxes either, so you need to target the actual sibling .tab-labels
first, and then the labels inside that.
The labels don't currently have IDs - you could add some, or you target them via the content of their for
attribute.
.tabs {
display: block;
flex-direction: column;
padding-right: 1em;
}
.tabs .tab-labels {
display: flex;
gap: 3px;
}
.tabs input[type="radio"] {
display: none;
}
.tabs label {
font-size: 15px;
padding: 0.25em;
background: #353235;
border-left: 10px;
cursor: pointer;
}
.tabs input[type="radio"]:checked + label {
background-color: #4a4a4a;
border-bottom: 2px solid blue;
}
.tab-content {
padding-left: 1em;
border: 5px solid gray;
display: none;
background: #353935;
}
/* Show tab content when corresponding radio button is checked */
#tab1:checked ~ #content1,
#tab2:checked ~ #content2,
#tab3:checked ~ #content3 {
display: block;
}
/* format the tab label corresponding to the checked radio button */
#tab1:checked ~ .tab-labels [for="tab1"],
#tab2:checked ~ .tab-labels [for="tab2"],
#tab3:checked ~ .tab-labels [for="tab3"] {
color: red;
}
<div class="tabs">
<input type="radio" id="tab1" name="tabs" checked>
<input type="radio" id="tab2" name="tabs">
<input type="radio" id="tab3" name="tabs">
<div class="tab-labels">
<label for="tab1">Tab 1</label>
<label for="tab2">Tab 2</label>
<label for="tab3">Tab 3</label>
</div>
<div id="content1" class="tab-content">
<h2>Tab 1</h2>
<p>This is the content for Tab 1.</p>
</div>
<div id="content2" class="tab-content">
<h2>Tab 2</h2>
<p>This is the content for Tab 2.</p>
</div>
<div id="content3" class="tab-content">
<h2>Tab 3</h2>
<p>This is the content for Tab 3.</p>
</div>
</div>