How to write a:hover in inline CSS?

后端 未结 23 2546
孤城傲影
孤城傲影 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:47

    So this isn't quite what the user was looking for, but I found this question searching for an answer and came up with something sort of related. I had a bunch of repeating elements that needed a new color/hover for a tab within them. I use handlebars, which is key to my solution, but other templateing languages may also work.

    I defined some colors and passed them into the handlebars template for each element. At the top of the template I defined a style tag, and put in my custom class and hover color.

    <style type="text/css">
        .{{chart.type}}-tab-hover:hover {
            background-color: {{chart.chartPrimaryHighlight}} !important;
        }
    </style>
    

    Then I used the style in the template:

    <span class="financial-aid-details-header-text {{chart.type}}-tab-hover">
       Payouts
    </span>
    

    You may not need the !important

    0 讨论(0)
  • 2020-11-21 23:47

    I had to avoid javascript, but could go with server side code.

    so I generated an id, created a style block, generated the link with that id. Yes its valid HTML.

    a {
      text-decoration: none;
      color: blue; 
    }
    
    a:hover {
      color: blue;
      font-weight: bold;
    }
    <!-- some code in the interpreter you use, to generate the data-hover id -->
    <style>
      a[data-hover="rnd-id-123"] { color: green;  } 
      a[data-hover="rnd-id-123"]:hover { color: red; }
    </style>
    <a data-hover="rnd-id-123">some link 1</a>
    
    <br>
    
    <!-- some code in the interpreter you use, to generate the data-hover id -->
    <style>
      a[data-hover="rnd-id-456"] { color: purple;  }
      a[data-hover="rnd-id-456"]:hover { color: orange; }
    </style>
    <a data-hover="rnd-id-456">some link 2</a>

    0 讨论(0)
  • 2020-11-21 23:56

    This is pretty late in the game, but when would you use JavaScript in an HTML Email? For example, at the company I currently work for (rhymes with Abodee), we use the lowest common denominator for most email marketing campaigns – and JavaScript is just not being used. Ever. Unless you are referring to some kind of pre-processing.

    As mentioned in a related post: "Lotus Notes, Mozilla Thunderbird, Outlook Express, and Windows Live Mail all seem to support some sort of JavaScript execution. Nothing else does."

    Link to the article from which this was taken: [http://en.wikipedia.org/wiki/Comparison_of_e-mail_clients]

    Also, how would hovering translate to mobile devices? That's why I like the answer from above:Long answer: you shouldn't.

    If anyone has more insights into this subject, please feel free to correct me. Thank you.

    0 讨论(0)
  • 2020-11-21 23:56

    It's now possible with Hacss.

    0 讨论(0)
  • 2020-11-21 23:56

    You can do id by adding a class but never inline.

    <style>.hover_pointer{cursor:pointer;}</style>
    <div class="hover_pointer" style="font:bold 12pt Verdana;">Hello World</div>
    

    2 lines but you can re-use the class everywhere.

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