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

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

I want to create something like


    
        aaa
        bbb
    
          


        
18条回答
  •  深忆病人
    2020-11-22 08:21

    As Michael suggested in the comments, what you want to do is quite possible, but your nomenclature is wrong. You aren't "adding tags to HTML 5," you are creating a new XML document type with your own tags.

    I did this for some projects at my last job. Some practical advice:

    1. When you say you want to "add these to HTML 5," I assume what you really mean is that you want the pages to display correctly in a modern browser, without having to do a lot of work on the server side. This can be accomplished by inserting a "stylesheet processing instruction" at the top of the xml file, like . Replace "menu.xsl" with the path to the XSL stylesheet that you create to convert your custom tags into HTML.

    2. Caveats: Your file must be a well-formed XML document, complete with XML header . XML is pickier than HTML about things like mismatched tags. Also, unlike HTML, tags are case-sensitive. You must also make sure that the web server is sending the files with the appropriate mime type "application/xml". Often the web server will be configured to do this automatically if the file extension is ".xml", but check.

    3. Big Caveat: Finally, using the browsers' automatic XSL transformation, as I've described, is really best only for debugging and for limited applications where you have a lot of control. I used it successfully in setting up a simple intranet at my last employer, that was accessed only by a few dozen people at most. Not all browsers support XSL, and those that do don't have completely compatible implementations. So if your pages are to be released into the "wild," it's best to transform them all into HTML on the server side, which can be done with a command line tool, or with a button in many XML editors.

提交回复
热议问题