HTML:空粗体标签后的文本也以粗体格式显示
我试图理解为什么浏览器会这样。
我在 html 文档中有以下文本。
<html>
<body>
This is Sample Text. <B/>Text after empty bold tag.
</body>
</html>
如果我在浏览器中查看该文档,它的显示如下所示。
这是示例文本。 空粗体标签后的文本。
为什么会发生这种情况?毕竟,我没有将任何文本标记为粗体。
I am trying to understand why browser behaves like this.
I have following text in html document.
<html>
<body>
This is Sample Text. <B/>Text after empty bold tag.
</body>
</html>
If I view this document in browser, it is displayed as shown below.
This is Sample Text. Text after empty bold tag.
Why is this happening? Afterall, I did not mark any text as bold.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要编写有效的 html 代码才能正确使用开始和结束标记。因此,您需要在所需的粗体文本之前编写一个开始标记 (
),并在文本之后编写一个结束标记 ()。
请注意,在您的示例中,您使用的
既不是有效的开始或结束标记,但在某些浏览器中可能会被解释为开始标记。
You need to write valid html code for this to work correctly with opening and closing tags. So you would need to write an opening tag (
<B>
) before the text you want in bold and a closing tag () after the text.Notice that in your example you are using
<B/>
which is neither a valid opening or closing tag but which may be interpreted as an opening tag in certain browsers.不是结束标记。
是结束标记。
是一个开始标签,其中有一个无用的斜杠。
<b/>
is not a closing tag.</b>
is a closing tag.<b/>
is an opening tag with a useless slash in it.我认为它的行为类似于自闭合标签
,它在标签定义之后应用所需的效果。看一下有关自关闭标签的主题:XHTML 中所有有效的自关闭元素是什么(由主要浏览器实现)?
我认为这也可能取决于您使用的浏览器。如果您在 Firefox 或 Chrome 中尝试此操作,众所周知,它们会尝试并纠正您的“错误编码”,因此它可能会认为这是一个拼写错误,并尝试以最好的方式纠正它。
I think it behaves like the self-closing tag
<br/>
which applies the desired effect after the tag definition.Take a look at this topic regarding self-closing tags: What are all the valid self-closing elements in XHTML (as implemented by the major browsers)?
I think this could also depend on the browser you're using. If you're trying this in firefox or chrome, they are known to try and correct you "bad coding", so it might be thinking it's a typo and trying to correct it the best way it can.