【问题标题】:how to add checked class for id of an input-tag in a other tag <label> or <p> or <a>如何在其他标签 <label> 或 <p> 或 <a> 中为输入标签的 id 添加检查类
【发布时间】:2021-11-04 18:20:35
【问题描述】:

我在做项目时遇到了问题。

为什么不为&lt;a&gt;&lt;label&gt;&lt;p&gt; 中的标签的ID 运行#MyId:checked~#show(style)

有没有办法为它运行css? 无需移除和移动label tag ,更改本例的#test:checked~#show即可正常运行。

#show {
  display: none;
  }
#test:checked~#show {
  display: block;
  }
<label>
 <input id="test" type="radio" value="0">click to show
</label>
<div id="show">
  hahahahahahha
</div>

【问题讨论】:

  • 您的输入在标签内,因此在 css 中没有办法

标签: html styles display radio checked


【解决方案1】:

否则你可以这样做:

#show {
  display: none;
  }
#test:checked~#show {
  display: block;
  }
<input id="test" type="checkbox"  >
<label for="test">click to show</label>
<div id="show">
  hahahahahahha
</div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-21
    • 2017-04-29
    • 1970-01-01
    • 1970-01-01
    • 2017-04-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多