What's the difference between and , and ?

前端 未结 22 1703
清酒与你
清酒与你 2020-11-22 08:10

What\'s the difference between and , and in HTML/XHTML? When should you use

22条回答
  •  礼貌的吻别
    2020-11-22 09:07

    As the others have stated, the difference is that and hardcode font styles, whereas and dictate semantic meaning, with the font style (or speaking browser intonation, or what-have-you) to be determined at the time the text is rendered (or spoken).

    You can think of this as a difference between a “physical” font style and a “logical” style, if you will. At some later time, you may wish to change the way and text are displayed, say, by altering properties in a style sheet to add color and size changes, or even to use different font faces entirely. If you've used “logical” markup instead of hardcoded “physical” markup, then you can simply change the display properties in one place each in your style sheet, and then all of the pages that reference that style sheet get changed automatically, without ever having to edit them.

    Pretty slick, huh?

    This is also the rationale behind defining sub-styles (referenced using the style= property in text tags) for paragraphs, table cells, header text, captions, etc., and using

    tags. You can define physical representation for your logical styles in the style sheet, and the changes are automatically reflected in the web pages that reference that style sheet. Want a different representation for source code? Redefine the font, size, weight, spacing, etc. for your "code" style.

    If you use XHTML, you can even define your own semantic tags, and your style sheet would do the conversions to physical font styles and layouts for you.

提交回复
热议问题