There is a useful way to highlight an HTML element/tag(a) in a certain color

Asked

Viewed 452 times

2

Well, I want to define a color tag style.

The following example changes the style of an element

<p id="tag"> parágrafo </p> 

To change the style of an HTML element, this syntax is used:

<script>
   document.getElementById("tag").style.color = "blue";
</script>

So far so good, but I wish I could set a direct color on the tag displayed on the page

Then it would be syntax below, which puts the HTML element visible on the web page.

&lt;p&gt; parágrafo &lt;/p&gt;

Result of the above syntax, its output is as in the line below

<p> parágrafo </p> 

So I want you to <p> and </p> have defined color, stipulated by me, for example - blue

3 answers

7


You can use the selectors before and after:

.paragraphClass::before, .paragraphClass::after{
  color: blue;
}
.paragraphClass::before{
  content: '<p>';
}
.paragraphClass::after{
  content: '</p>';
}
<div class="paragraphClass">foo</div>

0

Follow another alternative.

body {
    background-color: lightblue;
    font-size: 10pt;
}

#code {
    background-color: whitesmoke;
}


samp { color: tomato; }
<strong>Exemplo: o Meu Primeiro código de mark-up</strong>

<pre id="code">

    <samp>&lt;html&gt;</samp> 

      <samp>&lt;head&gt;</samp>

        <samp>&lt;title&gt;</samp> Título <samp>&lt;/title&gt;</samp>

      <samp>&lt;/head&gt;</samp>

        <samp>&lt;body&gt;</samp>

          <samp>&lt;p&gt;</samp> parágrafo <samp>&lt;/p&gt;</samp>

        <samp>&lt;/body&gt;</samp>

    <samp>&lt;/html&gt;</samp>

</pre>

This tag samp represents an output of a computational result.

0

You can define a CSS rule for the tag itself.

p {
  color: #F00;
}

So all the tags p will turn red color.

  • So Marcos the real function I need and have come to the conclusion is post-processing is code mark-up, or code marking. As I described in my question, in fact it would not be the internal element of the HTML document, that is, it would not be the tag itself, but rather on the page itself as text, without any interference in the HTML. The two answers were exactly what I was looking for. : D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.