Rails link_to with inline styling

前端 未结 8 1544
傲寒
傲寒 2020-12-15 16:30

I must change a link_to tag color without using a CSS class, how can I do? I\'ve tried something such as

<%= link_to item.description, {}, {:style=>\'c         


        
相关标签:
8条回答
  • 2020-12-15 16:39

    If you have a class called test-color, you can assign the :hover selector to that class by joining the class name and the :hover selector together.

    Class hooks begin with a dot(.), IDs begin with a hash(#)

    .test-color:link {
      color: #333333;
    }
    .test-color:visited {
      color: #FFFFFF;
    }
    .test-color:hover {
      color: #CCCCCC;
    }
    .test-color:active {
      color: #333333;
    }
    
    0 讨论(0)
  • 2020-12-15 16:46

    This should work with Rails 3

    link_to item.description, :style=> 'color:#FFFFFF;', :class => 'css_class'
    

    With the new syntax in rails 4, it becomes

    link_to item.description, style: 'color:#FFFFFF;', class: 'css_class'
    
    0 讨论(0)
  • 2020-12-15 16:48

    try this:

    = link_to name, url, style: 'color:#FFFFFF;'
    
    0 讨论(0)
  • 2020-12-15 16:50

    I am pretty sure this code will work.

    <%= link_to "button_name",{:controller => 'controller_name', :action => 'action_name'},{:style=>"color:#fff;"}%>

    0 讨论(0)
  • 2020-12-15 16:56

    link_to can be written as

    <%= link_to text, path, class: "" %>
    

    Or

    <%= path, class: "" do %>
      <div>
        <!-- Insert HTML here -->
      </div>
    <% end %>
    
    0 讨论(0)
  • 2020-12-15 16:58

    How about

    <%= link_to item.description, nil, {:style=>'color:#FFFFFF;', :class => "css_class"} %>
    

    ...or...

    <%= link_to item.description, '#', {:style=>'color:#FFFFFF;', :class => "css_class"} %>
    
    0 讨论(0)
提交回复
热议问题