【问题标题】:Is it possbile to make heart shaped input html button/element?是否可以制作心形输入html按钮/元素?
【发布时间】:2021-09-16 20:55:58
【问题描述】:

是否可以自定义常规 <input tupe="checkbox"> ?假设我希望它是心形输入元素,并且当它被选中时会改变颜色。

我在看这 2 篇文章,首先是 MDN 上的 documentation,但我没有看到任何可以帮助我的东西。有什么我想念的吗?

【问题讨论】:

标签: html css


【解决方案1】:

使用input { display none; } 隐藏复选框本身。然后在标签中以 SVG 或 HTML/Unicode 的形式添加心脏。您可以使用 input:checked ~ label 作为选择器在 CSS 中添加更改。

/* hides the checkbox */
input {
  display: none;
}

/* changes the color when selected */
input:checked ~ label {
  color: red;
}



/* for styling purpose only */
label {
  font-size: 5em;
}
<input type="checkbox" id="heart">
<label for="heart">&#9829</label>

【讨论】:

  • 谢谢。所以我需要隐藏复选框本身并将其“伪造”为标签。
猜你喜欢
  • 2012-11-19
  • 2011-05-31
  • 2019-09-19
  • 1970-01-01
  • 1970-01-01
  • 2013-09-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多