和< div />有区别吗?和< div>< / div>? [英] Is there a difference between <div /> and <div></div>?

查看:233
本文介绍了和< div />有区别吗?和< div>< / div>?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的网页上遇到问题,其中母版页的页脚未能正确显示某个特定页面。在该页面上,我有一个



< div style =clear:both/> 底部。

在看了一段时间之后,我看到我需要改变脚步才能正确显示脚步,就是将该行改为:

 < div style =clear:both>< / div> 

我不明白为什么用这种方式编写它会产生不同的结果。它们在语义上不等价吗?我检查并仔细检查了这是我做出的唯一改变。在这两者之间来回翻转会改变页脚的行为。



所以我的问题是......那些不是等价的?它们之间的区别是什么?



编辑:奇怪的是,他们都按照我想要的那样在页面上方显示它们。我的意思是,在自闭div标签的情况下,如果我完全删除它,页面肯定会作出反应,所以它必须与它做一些事情,而不是完全忽略它。

解决方案

< div /> 不是有效的标记。您必须使用完整版本< div>< / div> $ c $。

一个自我封闭的div标签将毫无意义,因为它会导致一个空的div。大多数浏览器通常不会呈现空div。


Ran into a problem on my web page where the footer in the master page wasn't displaying correctly for one particular page. On that page, I had a

<div style="clear:both" /> at the bottom.

After banging my head at it for a while, I saw that all I needed to change to get the footer to show up properly was to change that line to:

<div style="clear:both"></div>

I don't understand why writing it this way should produce a different result. Aren't they semantically equivalent? I checked and double-checked that this was the only change I made. Flipping back and forth between the two would change the behavior of the footer.

So my question is... are those not equivalent? What's the difference between them?

Edit: The odd part is, they both do what I want to the stuff above them in the page. I mean, in the self-closing div tag's case, if I remove it entirely the page definitely reacts, so it must be doing SOMETHING with it and not just ignoring it completely.

解决方案

<div /> is not a valid markup. A self-closing tag is not permitted.

You need to use the full version <div></div>.

A self closing div tag would make no sense, since it will result in an empty div. An empty div is usually not rendered by most of the browsers.

这篇关于和&lt; div /&gt;有区别吗?和&lt; div&gt;&lt; / div&gt;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆