gpt4 book ai didi

javascript - 如何将单选按钮变成 CSS 按钮?

转载 作者:太空宇宙 更新时间:2023-11-04 10:46:18 25 4
gpt4 key购买 nike

如何使下面的单选按钮看起来像按钮?

ruby

<%= simple_form_for(@challenge) do |f| %>
<%= f.text_field :action, placeholder: 'Enter a Custom Challenge' %>
Or choose a featured challenge:
<%= f.input :action, collection: ['Lose 10 Pounds', 'Exercise'], as: :radio_buttons %>
<% end %>

现在我让它看起来像一个按钮,但我无法让它工作。例如,当我单击该框时,背景不会变成黄色并且 radio [input] 不会被选中。

换句话说,我想要这个:

http://jsfiddle.net/YB8UW/654/

像这样工作:

http://jsfiddle.net/YB8UW/8/

CSS

.challenge_action {
list-style-type:none;
margin:25px 0 0 0;
padding:0;
}

.challenge_action span {
float:left;
margin:0 5px 0 0;
width:100px;
height:40px;
position:relative;
}

.challenge_action label, .challenge_action input {
display:block;
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
}

.challenge_action input[type="radio"] {
opacity:0.011;
z-index:100;
}

.challenge_action input[type="radio"]:checked + label {
background:yellow;
}


.challenge_action label {
padding:5px;
border:1px solid #CCC;
cursor:pointer;
z-index:90;
}

.challenge_action label:hover {
background:#DDD;
}

HTML

<div class="form-group radio_buttons optional challenge_action">
<span class="radio">
<label for="challenge_action_lose_10_pounds">
<input class="radio_buttons optional" type="radio" value="Lose 10 Pounds" name="challenge[action]" id="challenge_action_lose_10_pounds" />Lose 10 Pounds
</label>
</span>
<span class="radio">
<label for="challenge_action_exercise">
<input class="radio_buttons optional" type="radio" value="Exercise" name="challenge[action]" id="challenge_action_exercise" />Exercise
</label>
</span>
</div>

最佳答案

只需使用 collection_radio_buttons 参见 herehere详情

f.collection_radio_buttons :action, [['Lose 10 Pounds','Lose 10 Pounds'], ['Exercise','Exercise']], :first, :last

关于javascript - 如何将单选按钮变成 CSS 按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35368936/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com