te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>Unable to have Highlight on Selected CSS Tab on Tiddlywiki - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Unable to have Highlight on Selected CSS Tab on Tiddlywiki - Stack Overflow

programmeradmin4浏览0评论

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.
Add a comment  | 

1 Answer 1

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>

发布评论

评论列表(0)

  1. 暂无评论