Why does CSS work with fake elements?

前端 未结 19 730
野的像风
野的像风 2020-11-28 01:21

In my class, I was playing around and found out that CSS works with made-up elements.

Example:

相关标签:
19条回答
  • 2020-11-28 01:58

    While browsers will generally relate CSS to HTML tags regardless of whether or not they are valid, you should ABSOLUTELY NOT do this.

    There is technically nothing wrong with this from a CSS perspective. However, using made up tags is something you should NEVER do in HTML.

    HTML is a markup language, which means that each tag corresponds to a specific type of information.

    Your made up tags don't correspond to any type of information. This will create problems from web crawlers, such as Google.

    Read more information on the importance of correct markup.

    Edit

    Divs refer to groups of multiple related elements, meant to be displayed in block form and can be manipulated as such.

    Spans refer to elements that are to be styled differenly than the context they are currently in and are meant to be displayed inline, not as a block. An example is if a few words in a sentence needs to be all caps.

    Custom tags do not correlate to any standards and thus span/div should be used with class/ID properties instead.

    There are very specific exemptions to this, such as Angular JS

    0 讨论(0)
提交回复
热议问题