How can I apply CSS on all buttons which are present in that page?

后端 未结 5 1528
慢半拍i
慢半拍i 2020-12-08 16:46

I have created a CSS style class:

.btn { 
  color:#050; 
  font: bold 84% \'trebuchet ms\',helvetica,sans-serif; 
  background-color:#fed; 
  border:1px soli         


        
相关标签:
5条回答
  • 2020-12-08 17:12
    input[type=submit], input[type=button], button {
       ...
    }
    
    0 讨论(0)
  • 2020-12-08 17:13

    just a note

    input[type="button"]
    

    isn't going to work on old browsers like IE6. If that's a problem you will unfortunately need to add your class to each item.

    0 讨论(0)
  • 2020-12-08 17:16
    button{ 
      color:#050; 
      font: bold 84% 'trebuchet ms',helvetica,sans-serif; 
      background-color:#fed; 
      border:1px solid; 
      border-color: #696 #363 #363 #696; 
    } 
    

    OR

    input[type="button"]{ 
      color:#050; 
      font: bold 84% 'trebuchet ms',helvetica,sans-serif; 
      background-color:#fed; 
      border:1px solid; 
      border-color: #696 #363 #363 #696; 
    } 
    
    0 讨论(0)
  • 2020-12-08 17:18

    If your buttons are <input type="button"> or submit, then this should do it:

    input[type="button"], input[type="submit"] { 
        color:#050; 
        font: bold 84% 'trebuchet ms',helvetica,sans-serif; 
        background-color:#fed; 
        border:1px solid; 
        border-color: #696 #363 #363 #696; 
    } 
    

    Otherwise, if your buttons are <button>:

    button { 
        color:#050; 
        font: old 84% 'trebuchet ms',helvetica,sans-serif; 
        background-color:#fed; 
        border:1px solid; 
        border-color: #696 #363 #363 #696; 
    }
    

    To grab all three kinds of buttons:

    button, input[type="button"], input[type="submit"] { 
        color:#050; 
        font: bold 84% 'trebuchet ms',helvetica,sans-serif; 
        background-color:#fed; 
        border:1px solid; 
        border-color: #696 #363 #363 #696; 
    } 
    
    0 讨论(0)
  • 2020-12-08 17:23

    If you don't want to explicitly set all the styles, but want to use the styles already defined in some pre-existing class (for example the bootstrap btn-default class), you could do something like this:

    <script>
    $("button").addClass("btn-default");
    </script>
    

    In my case this was what I was looking for, although I'm sure there is some sort of caveat about doing it this way, or you'd expect it was something doable directly from CSS.

    0 讨论(0)
提交回复
热议问题