简体   繁体   English

firefox 在 html 中创建一个额外的标签

[英]firefox creating an extra a tag in html

Sorry for the little information on the title, Here's my html:抱歉,标题上的信息很少,这是我的 html:

<body>
<header class="header">
    <nav class="flex flex-jc-sb flex-ai-c">
        <a href="#" class="header__logo">
            <img src="img/logo.svg" alt="">
        </a>

        <a href="#" class="header__menu">
            <span></span>
            <span></span>
            <span></span>
        </a>

        <div class="header__links">
            <a href="#">Home</a>
            <a href="#">About</a>
            <a href="#"><a>
            <a href="#">Blog</a>
            <a href="#">Careers</a>
        </div>

        <a class='btn' href="#">Button</button>
    </nav>
</header>
<body>

but firefox is creating an extra a tag outside the header inside the body, same as the last one: <a class='btn' href="#">Button</button> .但是 firefox 在体内的 header 之外创建了一个额外的 a 标签,与最后一个相同: <a class='btn' href="#">Button</button>

chromium is also acting same铬也有同样的作用

If you use HTML Validation service , you will find bunch of problems, among others:如果您使用HTML 验证服务,您会发现一堆问题,其中包括:

Unclosed element a.
From line 22, column 9; to line 22, column 32

↩↩        <a class='btn' href="#">Button

Here you opened <a> tag, but incorrectly closed it with </button>在这里您打开了<a>标签,但用</button>错误地关闭了它

<a class='btn' href="#">Button</button>

so browser will do best effort to figure out correct DOM所以浏览器会尽最大努力找出正确的 DOM

Make sure you are opening and closing the right tags.确保您打开和关闭正确的标签。 It is not making an extra tag, it is closing the tag since you are closing an undefined button, not the actual anchor tag.它没有制作额外的标签,它正在关闭标签,因为您正在关闭未定义的按钮,而不是实际的锚标签。

You can fix this by replacing <a class='btn' href="#">Button</button> with <a class='btn' href="#">Button</a> .您可以通过将<a class='btn' href="#">Button</button>替换为<a class='btn' href="#">Button</a>来解决此问题。

It is not a browser issue, it is a code issue.不是浏览器问题,是代码问题。

Always make sure that you are opening and closing the correct tags.If you open an anchor tag then you should have close that and if you open button tag then you should have close that too始终确保您打开和关闭正确的标签。如果您打开一个锚标签,那么您应该关闭它,如果您打开按钮标签,那么您也应该关闭它
You can fix this by replacing Button with Button.您可以通过将 Button 替换为 Button 来解决此问题。

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

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