【问题标题】:Radio button not selectable after styling as a button将单选按钮设置为按钮后无法选择
【发布时间】:2015-03-11 10:27:11
【问题描述】:

我一直在尝试为表单上的一些单选按钮设置样式,但自从设置了样式后,我似乎无法选择它们...

我的 CSS 是:

.radio-toolbar input[type="radio"] {
  display: none;
  margin: 10px;
  // text-align: center;
}
.radio-toolbar label {
  display: inline-block;
  background-color: transparent;
  border-style: solid;
  border-width: 1px;
  border-color: white;
  padding: 8px 50px;
  color: white;
}
.radio-toolbar input[type="radio"]:checked + label {
  background-color: white;
  color: gray;
}

单选按钮是 (HAML):

.form-group
      .col-sm-10.radio-toolbar
        - YearGroup.all.each do |year_group|
          = f.radio_button(:year_group_id, year_group.id)
          = label_tag dom_id(year_group), year_group.name
      = f.label :year_group

关于为什么我不能选择它们的任何想法?

【问题讨论】:

  • 我不知道标签是否设置了for属性,因为我不熟悉HAML,但这可能是原因
  • 我不确定你的意思?我从这里得到了 CSS:stackoverflow.com/a/4642152/4262212
  • 您渲染的标签是否具有for 属性,例如<label **for="radio1"**>
  • 是的,它是

标签: css haml


【解决方案1】:

使用opacity:0 而不是display:none

.radio-toolbar input[type="radio"] {
  opacity:0; 
  margin: 10px;
  // text-align: center;
}

【讨论】:

  • 这只是隐藏了单选按钮,但没有使标签可点击?
猜你喜欢
  • 2018-09-17
  • 2018-07-08
  • 1970-01-01
  • 2018-07-07
  • 1970-01-01
  • 2016-09-24
  • 1970-01-01
相关资源
最近更新 更多