0

If i insert two closed empty div , i get one nested in another after render.

Source:

<html>
<head></head>
<body>
    <div id="up"/> 
    <div id="prop"/> 
</body>
</html>

Render:

<html>
<head></head>
<body>
    <div id="up">
        <div id="prop"></div>
    </div>
</body>
</html>

But when i insert first block as opening and closing tag, this is not happen:

Source:

<html>
<head></head>
<body>
    <div id="up"> </div>
    <div id="prop"/> 
</body>
</html>

Render:

<html>
<head></head>
<body>
    <div id="up"></div>
    <div id="prop"></div>
</body>
</html>

Why this happen?

Harry
  • 87,580
  • 25
  • 202
  • 214
Georgy Grigoryev
  • 822
  • 2
  • 8
  • 26
  • possible duplicate of [Is it OK to use a self closing DIV tag?](http://stackoverflow.com/questions/7971716/is-it-ok-to-use-a-self-closing-div-tag) and http://stackoverflow.com/questions/7757523/is-it-allowed-to-have-a-self-closing-div-tag-in-an-html-document – j08691 Sep 16 '13 at 13:21

3 Answers3

1

Maybe because you should always close your div tags?..

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div

Tag omission: None, both the starting and ending tag are mandatory.

pckill
  • 3,709
  • 36
  • 48
0

This is HTML not XML.

HTML does not support the closing of a TAG i.e. <div id=up"/>.

A well formatted Empty div should be as follows:

<div id="up"></div>
Scription
  • 646
  • 3
  • 12
  • 21
0

Be careful about the difference between HTML and XML!

HTML does not allow all tag-types to be closed "immediately", read this article for more info: http://tiffanybbrown.com/2011/03/23/html5-does-not-allow-self-closing-tags/

Maybe what you wanna use is XHTML for behaviour and syntax you would expect from XML.

olydis
  • 3,192
  • 13
  • 28