【发布时间】:2019-10-02 14:53:30
【问题描述】:
我希望能够单击标签来检查我的元素而不显示已选中,所以我写了这个:
input[type="checkbox"]
{
display: none;
}
但是当我点击它不起作用。仅当元素已在数据库中时才有效。
我必须做 javascript 还是 CSS 可以做?
#views/values/edit.html.erb*
<% @values =["Power", "Independance", "Tradition"] %>
<%= form_for @resultvalue do |f| %>
<% @values.each do | value | %>
<%= f.check_box :values, { multiple: true }, value, type:"checkbox" %>
<%= f.label value %>
<% end %>
<%= f.submit%>
<% end %>
input[type="checkbox"]{
display: none;
}
input[type="checkbox"]+label{
transition: all 300ms ease;
font-size: 1.2rem;
cursor: pointer;
border-radius: 1rem;
border: 3px solid white;
background-color: #0066cc;
padding: 0.5rem 1rem;
display: inline-block;
color: white;
// Suggested by @zizzo to prevent text selection
-moz-user-select: -moz-none;
-khtml-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
user-select: none;
// ------------------------
}
input[type="checkbox"]:checked+label{
transition: all 300ms ease;
background-color:#b70e7e;
}
【问题讨论】:
标签: javascript css ruby-on-rails sass ruby-on-rails-5