【问题标题】:The correct selector for all radio buttons Css所有单选按钮 Css 的正确选择器
【发布时间】:2016-12-21 18:04:15
【问题描述】:

这是在 CSS 中设置单选按钮样式的正确方法吗?

input [type = radio] {

<!-- Css stuff -->

}

【问题讨论】:

  • @Xufox 谢谢,方括号内的空格呢。
  • 那些可能没什么区别,但我还是会删除它们,只是为了确定。
  • 正确的做法是带引号:input[type="radio"]

标签: html css


【解决方案1】:

您应该删除空格。它们在 CSS 中具有意义——类似于“所有元素”。因此,您的选择器正在执行您不想要的额外功能。应该是:input[type="radio"]

此外,“正确”可以有多种含义。例如,将 HTML 更改为 &lt;input type="radio" class="radio-btn"&gt; 然后在 CSS 中使用 .radio-btn 可能更有意义。

【讨论】:

    【解决方案2】:
    input[type=radio]
    {
      /*all styles here applied here*/
    }
    

    【讨论】:

      【解决方案3】:

      这是正确的。

      input[type="radio"] {
      
      }
      

      input[type="radio"]:checked {
      
      }
      

      设置所选版本的样式。您需要删除input[type = radio] 之间的空格。

      【讨论】:

        【解决方案4】:
        input[type="radio"]
        

        不要忘记引号

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2022-01-17
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-09-27
          相关资源
          最近更新 更多