【问题标题】:input[type=radio]:checked + label with background-position-y doesn't work in Firefoxinput[type=radio]:checked + label with background-position-y 在 Firefox 中不起作用
【发布时间】:2016-07-02 12:53:50
【问题描述】:

CSS 选择器 input[type=radio]:checked + label 仅在 Firefox 中不起作用!

label {
  display: block;
  font-family: 'Muli';
  font-size: 14px;
  color: #666;
  vertical-align: top;
  background: url("https://s31.postimg.org/w3j8tei7f/bullet.png") no-repeat;
  background-size: 12px 52px;
  background-position-y: 1px;
  margin-bottom: 2px;
}
label:hover {
  cursor: pointer;
}
input[type=radio] + label {
  padding-left: 15px;
}
input[type=radio]:checked + label {
  background-position-y: -40px;
}
<div class="vol-radio">
  <input type="radio" name="volchoice-dates" id="volchoice-dates-flexibles" value="0" checked>
  <label for="volchoice-dates-flexibles">Dates flexibles</label>
  <input type="radio" name="volchoice-dates" id="volchoice-direct" value="1">
  <label for="volchoice-direct">Vol direct</label>
</div>

如何解决?

【问题讨论】:

    标签: html css firefox background-position


    【解决方案1】:

    background-position-xbackground-position-ylevel 4 CSS

    • 已解决:background-position-x/-ybackground-repeat-x/-y 获准为backgroundsborders 的第4 级。
    • background-size-x/-y 也被讨论过,但没有得到太多 支持。

    Firefox 不支持(,它将在 FF 版本 50 中),请参阅 Can I Use


    您可以改用background-position

    input[type=radio]:checked + label {
      background-position: 0 -40px; /* background-position-x | background-position-y  */
    }
    

    label {
      display: block;
      font-family: 'Muli';
      font-size: 14px;
      color: #666;
      vertical-align: top;
      background: url("https://s31.postimg.org/w3j8tei7f/bullet.png") no-repeat;
      background-size: 12px 52px;
      background-position: 0 1px;
      margin-bottom: 2px;
    }
    label:hover {
      cursor: pointer;
    }
    input[type=radio] + label {
      padding-left: 15px;
    }
    input[type=radio]:checked + label {
      background-position: 0 -40px;
    }
    <div class="vol-radio">
      <input type="radio" name="volchoice-dates" id="volchoice-dates-flexibles" value="0" checked>
      <label for="volchoice-dates-flexibles">Dates flexibles</label>
      <input type="radio" name="volchoice-dates" id="volchoice-direct" value="1">
      <label for="volchoice-direct">Vol direct</label>
    </div>

    【讨论】:

    • 你是说 Firefox 不支持 background-position-y 属性?
    • 非常感谢,迪帕斯
    • 不。如果您只是发布代码而没有解释,您有时会遭到反对。
    猜你喜欢
    • 2013-01-28
    • 2015-09-28
    • 1970-01-01
    • 2011-10-12
    • 1970-01-01
    • 2012-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多