Is there a way to create your own html tag in HTML5?

后端 未结 18 1617
情歌与酒
情歌与酒 2020-11-22 07:39

I want to create something like


    
        aaa
        bbb
    
          


        
18条回答
  •  醉酒成梦
    2020-11-22 08:13

    In some circumstances, it may look like creating your own tag names just works fine.
    However, this is just your browser's error handling routines at work. And the problem is, different browsers have different error handling routines!

    See this example.
    The first line contains two made-up elements, what and ever, and they get treated differently by different browsers. The text comes out red in IE11 and Edge, but black in other browsers.
    For comparison, the second line is similar, except it contains only valid HTML elements, and it will therefore look the same in all browsers.

    body {color:black; background:white;} /* reset */
    
    what, ever:nth-of-type(2) {color:red}
    code, span:nth-of-type(2) {color:red}

    test

    test

    Another problem with made-up elements is that you won't know what the future holds. If you created a website a couple of years ago with tag names like picture, dialog, details, slot, template etc, expecting them to behave like spans, are you in trouble now!

提交回复
热议问题