【问题标题】:Filling Button with a Radio Button [duplicate]用单选按钮填充按钮 [重复]
【发布时间】:2021-12-24 15:29:24
【问题描述】:

我想知道是否可以用单选按钮填充父按钮并删除默认单选按钮样式,保留按钮的单选按钮功能。

<button>
  <input type='radio' />
</button>

【问题讨论】:

  • 为什么。用例是什么?单击按钮时可以使用 JavaScript 设置隐藏字段
  • 基本上我使用 Formik 和 Yup 进行输入验证,需要三个单独的单选按钮来选择输入(不能使用按钮)
  • 显示 HTML 以及它需要做什么,我们有一个更好的主意。您要解决的问题是什么?听起来像是 X/Y 问题
  • 我只需要一个单选按钮(在 sn-p 所示的按钮中)来填充外部按钮样式。

标签: html css button parent fill


【解决方案1】:

跳跃这是期望的行为,这是我的解决方案:

button input[type="radio"] {
  /* Add if not using autoprefixer */
  -webkit-appearance: none;
  appearance: none;
  /* For iOS < 15 to remove gradient background */
  background-color: #fff;
  /* Not removed via appearance */
  margin: 0;
  width:100px;
}
<button>
  <input type='radio' />
</button>

【讨论】:

  • 不能作为单选按钮使用,因为它隐藏在 DOM 中,谢谢。
  • 我已经回答了你的问题。你没有提到你需要什么样的功能。
  • 应该更好地措辞这个问题,我需要它作为一个单选按钮,但感谢您的回复,赞成:)
猜你喜欢
  • 2013-05-01
  • 2011-12-25
  • 2020-10-27
  • 2012-03-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多