Search code examples
cssruby-on-railsrubytwitter-bootstraptwitter-bootstrap-rails

How to change the color of Bootstrap links


I am using twitter bootstrap and I have some code like this:

<%= link_to "Create", new_something_path %>

which renders the text in a light blue color, highlighting it as a link.

How would I reference that element to change it via css?


Solution

  • You can add a CSS class or id to a link_to by setting it in the html_options hash, which is the last parameter of the link_to helper.

    For example, using Ruby 1.9 hash syntax (convert to :key => 'value' if using Ruby 1.8):

    Just the CSS selector .new-something-class:

    <%= link_to "Create", new_something_path, class: 'new-something-class' %>

    or for a link with with the CSS selectors #new-something-id and .new-something-class:

    <%= link_to "Create", new_something_path, class: 'new-something-class', id: 'new-something-id' %>

    You could then reference this element in your .css file(s) as usual.