Home > database >  Css rule for comments inside html code tag?
Css rule for comments inside html code tag?

Time:11-24

How to set a css rule so I can format comments inside html code tags?
something like regex //.*

<pre>
  <code>
    git reset [file]        //unstage but preserve file content
    ...
  </code>
</pre>

CodePudding user response:

You can put the comments in tags:

.comment {
  color:grey;
  /*Your CSS here*/
}
<script src="https://css-library.hg0428.repl.co/script.js"></script>
<pre>
  <code>
    git reset [file] <span class="comment">//unstage but preserve file content</span>
    ...
  </code>
</pre>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

If you dont want to use tags then you will need to use JavaScript to loop through all the code tags, locate comments, and apply the class.

  • Related