简体   繁体   中英

rails how to place checkbox before label on collection checkbox?

Using this code:

  - @contacts.each do |contact|
    = label_tag "contact[#{contact.id}]", contact.slug
    = check_box_tag "contact[#{contact.id}]", contact.id
    .clear

Results in:

  <label for="contact_1">Avalon3323</label>
                    <input id="contact_1" name="contact[1]" type="checkbox" value="1" />
                    <div class='clear'></div>
                    <label for="contact_2">doutzen</label>
                    <input id="contact_2" name="contact[2]" type="checkbox" value="2" />
                    <div class='clear'></div>
                    <label for="contact_3">jannie6674</label>

Which seems okay according to the documentation.

Still the label is positioned before the checkbox. Does one have to fix this with CSS? Shouldn't the html order be correctly by itself?

have you tried to swap code?

= check_box_tag "contact[#{contact.id}]", contact.id
= label_tag "contact[#{contact.id}]", contact.slug

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM