簡體   English   中英

如何在復選框simple_form上添加標簽,以及如何在標簽上內聯設置標簽樣式?

[英]How to add a label on the checkbox simple_form and style the label inline to the checkbox?

我有一個沒有標簽的復選框。 我如何在simple_form中添加標簽標記,在復選框的HTML標簽標記中插入復選框。

我目前有復選框和純文本。

    <%= f.check_box :is_positive, as: :boolean, checked_value: true, unchecked_value: false %> Is positive?

我嘗試了下面的代碼,但是它使標簽高於實際的復選框。

    <%= f.input :is_positive, as: :boolean, checked_value: true, unchecked_value: false, inline_label: 'Is positive?' %>

有沒有辦法標記復選框並使其標簽內聯到復選框?

請嘗試下面的代碼,您可以使用css將標簽的樣式更改為所需的樣式:

<%= f.label :is_positive do %>
  <%= f.check_box :is_positive, as: :boolean, checked_value: true, unchecked_value: false %> <span class="labelText">Is positive?</span>
<% end %>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM