Assigning classes to elements through CSS

后端 未结 3 588
我在风中等你
我在风中等你 2020-12-09 01:32

I\'d like to tell the browser to assign certain CSS classes to elements matching a particular selector. Can I do it with pure CSS and if yes, how?

Example: I want al

相关标签:
3条回答
  • There is no way to assign this value to those elements in pure CSS.

    You would need to do:

    #sidebar h5
    {
    
    }
    

    Then copy all styles from ui-corners-all class into this.

    Or alternatively, change your ui-corners-all CSS to:

    .ui-corners-all, #sidebar h5
    {    
    
    }
    
    0 讨论(0)
  • 2020-12-09 02:05

    No, you can't. You can however use Javascript (jQuery recommended) to achieve this effect.

    0 讨论(0)
  • 2020-12-09 02:12

    No, that isn't possible with pure CSS.

    Only with JavaScript:

    // jQuery
    $("h5").addClass("ui-corners-all");
    
    // Pure JavaScript
    var elements = document.getElementsByTagName("h5");
    for (var i=0; i<elements.length; i++)
    {
      var el = elements[i];      
      el.setAttribute( "class", el.getAttribute("class") + " ui-corners-all" );
    }
    
    0 讨论(0)
提交回复
热议问题