Add icon to submit button in twitter bootstrap 2

后端 未结 12 1808
被撕碎了的回忆
被撕碎了的回忆 2020-12-04 05:44

I want to use the twitter bootstrap icons on my form input submit buttons.

The examples on http://twitter.github.com/bootstrap/base-css.html#icons mainly show style

12条回答
  •  感动是毒
    2020-12-04 05:59

    I wanted to the Twitter Bootstrap icons to a basic Rails form and came across this post. After searching around a bit, I figured out an easy way to do it. Not sure if you're using Rails, but here's the code. The key was to pass a block to the link_to view helper:

    
        <% @products.each do |product| %>
          
            <%= product.id %>
            <%= link_to product.name, product_path(product) %>
            <%= product.created_at %>
            
              <%= link_to(edit_product_path(product), :class => 'btn btn-mini') do %>
              Edit 
              <% end %>
    
              <%= link_to(product_path(product), :method => :delete, :confirm => 'Are you sure?', :class => 'btn btn-mini btn-danger') do %>
              Delete 
              <% end %>
            
          
        <% end %>
      
    
    
    <%= link_to(new_product_path, :class => 'btn btn-primary') do %>
        New 
    <% end %>
    

    In case you're not using Rails, here is the output HTML for the links with icons (for an edit, delete, and new submit buttons)

    # Edit
    Edit 
    
    # Delete
     Delete 
    
    # New
    New 
    

    And here's a link to screenshot of the finished result: http://grab.by/cVXm

提交回复
热议问题