简体   繁体   中英

Having trouble styling my Rails select menu

I'm using Rails 4.2.3. I want to change the font of a select menu but I'm having trouble doing it. I installed the “bootstrap-sass” gem and added this to my stylesheet …

select {
        font-family: 'Oxygen', sans-serif;
}

and then set up my select tag this way

<%= select_tag :state, options_for_select([["Select State", nil], *us_states]), {class: "form-control"} %>

but when my menu is rendered the options continue to have the normal font and not the one I specified. What else do I need to do to style my Rails select menu?

This should work for you:

<%= select_tag :state, options_for_select([["Select State", nil], *us_states]), class: 'states form-control' %>

You don't need to send it in a secondary hash.

I'd also consider adding a more identifiable class name for example:

.states {
    font-family: 'Oxygen', sans-serif;

}

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