0

In a CSS sheet, I created a new tag

gb {
    color: green;
}

and in the HTML code, I would replace without javascript, all occurences of

<gb> &#9632; </gb>  <!-- green bullet -->

with something like <gb /> . (Like using the C preprocessor, but doing thing in native HTML/CSS, without need to another program (cpp) and action (preprocessing) before sending the page on the web)

In other terms, how could I create custom HTML tag, with content (saving typing the &#9632; code), but only using HTML/CSS ?

And, yes, a lot of content already address custom HTML tags, but

  1. They generally use Javascript
  2. It is not clear
  3. I can't believe such a little thing could involve these cumbersome solutions.

The idea is just to have a short way to draw an Unicode symbol (and in color) in middle of text.

TylerH
  • 20,799
  • 66
  • 75
  • 101
yO_
  • 1,135
  • 2
  • 12
  • 18
  • 4
    It does not really matter whether you “can believe it” or not ... that doesn’t change the basic fact that this is not possible in any trivial way using HTML & CSS alone. – CBroe Jul 07 '17 at 10:15
  • 3
    HTML does not allow you to create custom elements (there is a custom element spec, but it is still a draft and your code doesn't conform to it) – Quentin Jul 07 '17 at 10:16
  • This is probably something best achieved with a `
  • ` and some styling of the natural bullet.
  • – Quentin Jul 07 '17 at 10:17
  • 1
    Basically you can write `` tag to HTML and it will act as normal `
    `.
    – Justinas Jul 07 '17 at 10:17
  • 1
    @Justinas — It won't. Error recovery will treat it more like a ``. It's still best avoided. – Quentin Jul 07 '17 at 10:18
  • You can do something like this - https://jsfiddle.net/3mabnomt/ but your markup is not valid. It's not recommended to create custom tags like that – Mr. Alien Jul 07 '17 at 10:18
  • @CBroe What with the answer below...? – yO_ Jul 07 '17 at 10:30
  • @Quentin Maybe, but the goal is to put this tag alone, in many locations in the document. – yO_ Jul 07 '17 at 10:32
  • 1
    @yO_ what about it? That is CSS generated content, yes. But that has absolutely nothing to do with custom elements of any sort. – CBroe Jul 07 '17 at 10:35
  • @CBroe Because we define a new `` tag, that is not in native HTML?.. – yO_ Jul 07 '17 at 10:38
  • 2
    Why you should not be doing that in the first place (especially if you don’t want to use any JavaScript), Quentin has already pointed out in comments. CSS generated content is a “feature” of CSS, yes. But is has no connection whatsoever with custom elements. This would work the same way if you applied it to a `div` for example. – CBroe Jul 07 '17 at 10:40
  • 2
    Why this question and answer are being downvoted? OP asked for a way to not duplicate symbols inside custom tags. Answer has been added. It's working and fits question. What's wrong? – Vadim Ovchinnikov Jul 07 '17 at 10:50