简体   繁体   English

HTML锚标签在Firefox,Safari,iPad和iPhone中无法使用

[英]HTML anchor tags not working in Firefox, Safari, iPad and iPhone

My html anchor tags work in chrome and IE but in Firefox, Safari, iPad and iPhone they do not work, how come? 我的html锚标签在chrome和IE中工作,但在Firefox,Safari,iPad和iPhone中它们不起作用,怎么样? and what can I do to fix it? 我该怎么做才能解决这个问题?

<a href="/services#underpinning">Underpinning</a>

Any help would be appreciated. 任何帮助,将不胜感激。

Thanks. 谢谢。

This is what I am trying to link it to on the services page: 这是我试图将其链接到services页面上的内容:

<h1 id="#underpinning" name="underpinning">Underpinning</h1>

This is where I left off: 这是我离开的地方:

This is my link: 这是我的链接:

<li><a href="/services#underpinning"><h2 id="underpinning">Underpinning<a href="services#underpinning"><img class="alignnone size-full wp-image-127" alt="home" src="http://powellgroupconstruction.com/wp-content/uploads/2013/12/home.jpg" width="500" height="337"></a></h2></a></li>

This is where on my services page I want the link to goto: 这是我的服务页面上我希望链接转到的地方:

<a name="underpinning"><h1 id="underpinning" name="underpinning">Underpinning</h1></a>

If I goto the url directly: http://powellgroupconstruction.com/services/#underpinning into safari or firefox, it works. 如果我直接转到网址: http//powellgroupconstruction.com/services/#underpinning到safari或firefox,它的工作原理。

There are several issues in your code. 您的代码中存在几个问题。 On your example website you're using HTML5 Doctype , so I'm just answering respectively with HTML5 in mind: 在您的示例网站上,您使用的是HTML5 Doctype ,所以我只是分别回答HTML5:

  1. Forget about name attribute in general and <a name> markup as link target in particular. 一般忘记name属性 ,特别是<a name>标记作为链接目标

    As the HTML5 Candidate Recommendation spec states: 正如HTML5候选推荐规范所述:
    "An element's unique identifier can be used for a variety of purposes, most notably as a way to link to specific parts of a document using fragment identifiers, as a way to target an element when scripting, and as a way to style a specific element from CSS." “元素的唯一标识符可用于各种目的,最明显的方式是使用片段标识符链接到文档的特定部分,作为在编写脚本时定位元素的方法,以及作为设置特定元素样式的方法来自CSS。“
    That means, you can use any id as a link target . 这意味着,您可以使用任何id作为链接目标

  2. As Itay Gal has already stated in his answer, don't use the same id more than once . 正如Itay Gal在他的回答中已经说过的, 不要多次使用相同的id From the HTML5 spec again: 再次从HTML5规范
    "The id attribute specifies its element's unique identifier (ID)" . “id属性指定其元素的唯一标识符(ID)”
    That said, change your current code: 也就是说,更改您当前的代码:
    <a id="underpinning" name="underpinning"><h1 id="underpinning" name="underpinning">Underpinning</h1></a>
    to
    <h1 id="underpinning">Underpinning</h1>

  3. You're using as link address currently /services#underpinning . 您目前使用的是链接地址/services#underpinning As you're going with the WordPress rewrite functionality, entering http://powellgroupconstruction.com/services gets redirected to http://powellgroupconstruction.com/services/ . 当你使用WordPress重写功能时,输入http://powellgroupconstruction.com/services会被重定向到http://powellgroupconstruction.com/services/
    Therefore you should better put a slash at the end of your pages' names , so the link address should be 因此,您最好在页面的名称末尾添加斜杠 ,因此链接地址应该是
    <a href="/services/#underpinning">Underpinning</a>

You are using the same id in multiple elements. 您在多个元素中使用相同的ID。 The id needs to be unique, make sure you use each id only once and it should work. id必须是唯一的,确保你只使用每个id一次,它应该工作。

Are href for both h2 and img tags are same? h2和img标签的href是否相同? then have you tried this one: 然后你试过这个:

    <a href="services#underpinning">
<h2 id="underpinning">Underpinning

<a href="services#underpinning"><img class="alignnone size-full wp-image-127"      alt="home" src="http://powellgroupconstruction.com/wp-content/uploads/2013/12/home.jpg"  width="500" height="337">
</a></h2>

    </a>

I had an issue very similar to this. 我有一个与此非常相似的问题。 I believe your problem is that Firefox and Safari do not like an <h2> tag inside an anchor <a> tag. 我相信你的问题是Firefox和Safari不喜欢锚<a>标签内的<h2>标签。 Try : 试试:

<a href="/services#underpinning"><span id="underpinning">Underpinning</span></a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM