html - 将文字置于图像之上

标签 html css

我有图像代替单选按钮输入。我想直接在这些图像上写文字,但我找不到实现此目的的简单方法。

我还需要在用作链接的图像之上进行书写,因此理想情况下最好采用一种在这两种情况下都适用的方式。

#selector {
  width: 5vw;
  vertical-align: middle;
}
input[type="radio"] {
display: none;
}
input[type="radio"]:checked + image {
border: 2px solid green;
}
<label>
  <input type="radio" name="amount" value="100" checked />
  <img id="selector" src="http://s8.postimg.org/k4wy7buc1/selector.png">100</label>
<label>
  <input type="radio" name="amount" value="250" />
  <img id="selector" src="http://s8.postimg.org/k4wy7buc1/selector.png">250</label>
<label>
  <input type="radio" name="amount" value="500" />
  <img id="selector" src="http://s8.postimg.org/k4wy7buc1/selector.png">500</label>
<label>
  <input type="radio" name="amount" value="1000" />
  <img id="selector" src="http://s8.postimg.org/k4wy7buc1/selector.png">1000</label>
<label>
  <input type="radio" name="amount" value="1500" />
  <img id="selector" src="http://s8.postimg.org/k4wy7buc1/selector.png">1500</label>

最佳答案

你有没有想过使用background-image

input[type="radio"] {
  display: none;
}
input[type="radio"]:checked + label {
  outline: 2px solid green;
}
label {
  background-image: url('http://s8.postimg.org/k4wy7buc1/selector.png');
  display: inline-block;
  background-size: 40px 20px;
  width: 40px;
  height: 20px;
}
<input id="rb1" type="radio" name="amount" value="100" checked />
<label for="rb1">100</label>
<input id="rb2" type="radio" name="amount" value="250" />
<label for="rb2">250</label>
<input id="rb3" type="radio" name="amount" value="500" />
<label for="rb3">500</label>
<input id="rb4" type="radio" name="amount" value="1000" />
<label for="rb4">1000</label>
<input id="rb5" type="radio" name="amount" value="1500" />
<label for="rb5">1500</label>

关于html - 将文字置于图像之上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35486283/

相关文章:

javascript - 响应式下拉菜单

html - 磨砂玻璃效果 : filter: blur()

python - 在 Django 中实现 CSS

html - 居中 div,边距 : 0 auto; not working

javascript - 仅更改 Framework7 中一个 radio 的非事件颜色?

html - 将内联 div 拖放到新行

html - Flex Growth 应该只占用可用空间并防止将长文本的 child 推出

javascript - 单击 rails link_to 后未触发 jQuery 准备就绪

javascript - 尝试使用 jquery fileUpload 时出现错误

javascript - 在内联 CSS 中使用 javascript 变量