【问题标题】:What is the correct alternative for the attribute "name"?属性“名称”的正确替代方法是什么?
【发布时间】:2012-08-10 21:04:24
【问题描述】:

当我使用 w3c 验证器验证此页面时,我被告知“名称属性已过时”,但是,我找不到替代方法。我能找到的每篇关于页面内链接的文章似乎仍然使用 name 属性来指定。验证器上提到的方法(链接到“id”)似乎对我不起作用。

任何人都知道正确的替代方案,或者如何正确链接到 id?

另外,我希望能够链接到当前锚点正上方的特定点...有什么方法可以更具体地说明页面滚动/跳转到的位置吗?

http://firewalkcreative.com/2012/2012.html

【问题讨论】:

标签: css html


【解决方案1】:

您可以像这样跳到具有指定标识符的任何元素:

<div id="navigation"></div>

<div id="content"></div>

<div id="footer"></div>

<a href="#navigation">Skip to navigation</a>

【讨论】:

    【解决方案2】:

    您可以使用类名或 id:

    <a id="top"></a>
    
    <a class="top"></a>
    

    或者您可以分配多个类以使其更具体

    <a class="link top"></a>
    

    或者使用 html5 你可以这样做:

    <a data-name="top" ></a>
    

    【讨论】:

    • 这与内部链接有关吗?您不能使用类名或属性进行内部链接
    • 所以在尝试了所有这些之后,它们都不起作用,我意识到它们确实起作用了,你是对的,问题出在我用来进行滚动的 smoothpack javascript 代码中...我没有写。当我把它拿走时,链接到一个 id 就可以了。关于使用 id 的滚动脚本的任何想法?
    【解决方案3】:

    在过去,speek html 4,您可以访问内部链接,例如:

    <a href="#bottom">link</a>
    

    目标是

    <a name="bottom"></a>
    

    现在我们这样做:

    <a href="#bottom">link</a>
    

    目标:

    <foo id="bottom"></foo>
    

    你看我使用 foo,因为它可以是你喜欢的任何元素

    【讨论】:

    • HTML 4.0.1 spec 说:The id attribute may be used to create an anchor at the start tag of any element (including the A element).
    猜你喜欢
    • 2023-04-09
    • 2011-05-20
    • 2020-08-06
    • 1970-01-01
    • 2017-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-22
    相关资源
    最近更新 更多