简体   繁体   中英

Set button to active on click?

I am trying to change the color of a button when I click it, but it does not work. The .radio_button:hover function works, but not the .radio_button:active . (I think the CSS is overridden by the bootstrap CSS, could that be the case (if so, how can I override the bootstrap css))?

form with button:

<table border="0" width="100%" cellpadding="5px">
  <tr>
    <td>
      <%= simple_form_for(@post, :html => {:class => 'form-inline' }) do |f| %>
      <%= f.input :link, label: false %>
      <%= f.input :tag_list, placeholder: "Add some tags...", label: false %>
      <div id="type_group" class="btn-group" data-toggle="buttons-radio">
        <%= f.input :type, as: :hidden %>
          <a class="radio_button" id="radio_button_zero" data-value="0">ZERO</a>
          <a class="radio_button" id="radio_button_one" data-value="1">ONE</a>
          <a class="radio_button" id="radio_button_two" data-value="2">TWO</a>
      </div>
      <%= button_tag(type: 'submit', class: "submit_button") do %>
        POST!
      <% end %>
      <% end %>
    </td>
  </tr>
</table>

CSS:

.radio_button {
        color: white;
        background-color:#828282;
        font-family: 'Fjalla One', serif;
        font-size: 10pt;
        font-weight: 100;
        text-align: center;
        font-style: italic;
        padding:0px 6px;
        padding-right: 8px;
        padding-top: 3px;
        padding-bottom: 2px;
        text-decoration:none;
        border: none;
    }.radio_button:hover {
        background-color:#0E9EBB;
        color: white;
        text-decoration:none;
    }.radio_button:active {
        position:relative;
        background-color:#0E9EBB;
        top:1px;
    }.radio_button,.btn:focus{
        outline:none!important
    }

coffeescript:

$ ->
  $("a.radio_button").click (e) ->
    e.preventDefault();
    clickedValue = $(this).data("value")
    $("#post_type").val clickedValue
    if clickedValue == 0
      $("#radio_button_zero").addClass('active')

have a look for all the changes

http://demo.sumedhasoftech.com/manoj/test/test.html

If u wanna override bootstrap css just include your css before bootstrap's ... or you can use jQuery ...

<style>
   .active {
      position:relative;  
      background-color:#0E9EBB;  /* u can use background-color:#0E9EBB!important;*/
      top:1px;
</style>

$('button').click(function (){
  $(this).addClass('active');
});

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