How to write a:hover in inline CSS?

后端 未结 23 2559
孤城傲影
孤城傲影 2020-11-21 23:15

I have a case where I must write inline CSS code, and I want to apply a hover style on an anchor.

How can I use a:hover in inline CSS inside the HTML st

23条回答
  •  长情又很酷
    2020-11-21 23:44

    using Javascript:

    a) Adding inline style

    document.head.insertAdjacentHTML('beforeend', '');
    

    b) or a bit harder method - adding "mouseover"

    document.getElementById("mydiv").onmouseover= function(e){this.className += ' my-special-class'; };
    document.getElementById("mydiv").onmouseleave= function(e){this.className = this.className.replace('my-special-class',''); };
    

    Note: multi-word styles (i.e.font-size) in Javascript are written together:

    element.style.fontSize="12px"

提交回复
热议问题