Should I make HTML Anchors with 'name' or 'id'?

前端 未结 14 1519
旧巷少年郎
旧巷少年郎 2020-11-22 00:49

When one wants to refer to some part of a webpage with the \"http://example.com/#foo\" method, should one use

F

14条回答
  •  天命终不由人
    2020-11-22 01:33

    In html 5, the id="" attribute defines a unique identifier for an element, which is also an anchor for a fragment link. In previous html standards, the name="" attribute of the element defines an anchor for a fragment link. I recommend something like:

    Foo Title


    Because support for the id="" attribute is a bit spotty(even though the latest releases of all major browsers support it, the releases that don't aren't more than a few years old[And it's best not to break something if there isn't a good reason to]). It's compatible, & it doesn't style whatever's in the link'd element, for the closing is still outside the element, but it's still valid in all current standards.

    Be sure that the name="" and id="" attributes of the element are the same.

提交回复
热议问题