我正在尝试使用 ninja 表单中的 CSS 修改格式。我想:
- 在单选按钮问题的每个答案上方添加一个图标/图像
- 允许用户单击该图像或文本来选择他们的答案
任何人都可以帮我处理这段代码吗?我无法让图像显示。
谢谢!
我正在尝试使用 ninja 表单中的 CSS 修改格式。我想:
任何人都可以帮我处理这段代码吗?我无法让图像显示。
谢谢!
我发现在单选按钮中放置图像的最简单方法是执行以下操作:
<img src="https://www.brothershelpingbrothers.org/wp-content/uploads/2015/08/silver-fire-button.png">
<div><img src="https://www.brothershelpingbrothers.org/wp-content/uploads/2015/08/silver-fire-button.png"><br>Button Label 1</div>
/* NINJA FORM CSS */
/* Display image buttons inline */
li {
display: inline-block !important;
}
/* Hide the radio button */
[type=radio] {
position: absolute;
opacity: 0;
width: 0;
height: 0;
}
/* RADIO BUTTON STYLES */
/* Style radio button images */
label > div > img {
cursor: pointer;
max-width: 100px !important;
max-height: 100px !important;
}
/* Style the text label */
label > div {
color: blue;
font-size: .8em;
text-align: center !important;
}
/* CHECKED STYLES */
/* Outlines Selected Radio Button */
.nf-checked-label {
outline: 3px solid pink;
}
我认为这段代码可以解决你的问题
function selectInput(id) {
$("#" + id).prop("checked", true);
}
img {
width: 50px;
height: 50px;
cursor: pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<img src="http://plainplastic.com/wp-content/uploads/2018/06/one-v2.png" onClick="selectInput('radio1')" />
<input id="radio1" type="radio" name="answer" value="Answer 1" />Answer 1
<img src="http://plainplastic.com/wp-content/uploads/2018/06/one-v2.png" onClick="selectInput('radio2')" />
<input id="radio2" type="radio" name="answer" value="Answer 2" />Answer 2
<img src="http://plainplastic.com/wp-content/uploads/2018/06/one-v2.png" onClick="selectInput('radio3')" />
<input id="radio3" type="radio" name="answer" value="Answer 3" />Answer 3
</div>