小编Cle*_*ana的帖子

可以在<input>控件布局之外的其他嵌套级别中使用<label>吗?

我想知道以下HTML / CSS是否有任何错误,主要是从可访问性的角度来看。

我有两组指令A和B。用户一次只能看到其中一条。当用户看到说明A时,应该有一个指向B的链接,反之亦然。我考虑过使用<radio>按钮及其:checked状态来控制内容的可见性,然后按钮<label>可能位于该内容内部,充当链接。由于可以单击标签来激活其相应的单选按钮,因此我将代码设置如下:

label {
  text-decoration: underline;
  color: blue;
  cursor: pointer;
}

.a,.b {
  display:none;
}

#a:checked ~ .content .a,
#b:checked ~ .content .b {
  display: block;
}
Run Code Online (Sandbox Code Playgroud)
<input type="radio" name="options" value="a" id="a" checked>
<input type="radio" name="options" value="b" id="b">

<div class="content">
  <div class="a">
    Some text and <label for="b">Check out B</label>
  </div>
  <div class="b">
    Some other text and <label for="a">Check out A</label>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

由于这似乎很骇人听闻,所以我想您可以指出该代码可能导致的任何潜在问题。

html css accessibility

5
推荐指数
1
解决办法
63
查看次数

标签 统计

accessibility ×1

css ×1

html ×1