0

Possible Duplicates:
What are all the valid self-closing tags in XHTML (as implemented by the major browsers)?
Are (non-void) self-closing tags valid in HTML5?
Why do browsers think this <div/> tag isn't immediately ended?

can someone please explain why this happens?

.lineBreak10
{
    height: 10px;
}

<div class="lineBreak10"/> --> does not work

<div class="lineBreak10"></div> --> works

bokkie
  • 1,477
  • 4
  • 21
  • 40

4 Answers4

7

This is not how divs are supposed to work. They are block-level elements, and you're supposed to be able to put stuff inside them.

Furthermore, it looks as though you're trying to use a div to create visual (stylistic) space between two elements. That's not what HTML is for. That's what CSS is for.

Jezen Thomas
  • 13,619
  • 6
  • 53
  • 91
  • 1
    While this is true, it doesn't really answer the question. – Williham Totland Apr 27 '12 at 09:18
  • ok, thanks....though I hope it is not a "wrong" approach to put space between controls...it is much easier to have a few of these classes with 10,20,40px... – bokkie Apr 27 '12 at 09:18
  • @bokkie: "Easy" doesn't mean "right". – Williham Totland Apr 27 '12 at 09:20
  • @WIllihamTotland I know, that's why I said I hope it is not wrong :) then what would be the better approach? use padding-top: x px on every control under this div? this would mean if I have 5 classes for the div(lineBreak10, lineBreak20, lineBreak40...) and I will decide not to use them anymore, I would have to make 5 of each other class I have? let's say I have a class for a label that gives it a color and font...then this means I would have to make other four of this class, each with a different padding-top? that means I would have many many classes...only if there is a different approach? – bokkie Apr 27 '12 at 09:28
  • @bokkie: Classes should refer to the purpose of the element within the context of the page and the content, not how it looks. Also, within any given document, spacing between various elements should be fairly consistent, so long as those elements are of the same type (e.g. spacing between h3 and p should be fairly consistent). CSS has a wealth of selectors, use them. – Williham Totland Apr 27 '12 at 09:33
4

Because HTML isn't XML.

While HTML looks a lot like XML, it is actually a completely separate thing, not bound by the same rules.

If you use XHTML, served as XML to the web browser, self-closing elements not working is a bug, but if you serve a document as HTML, all rules that relate to XML and HTML's similarities to same go out the window.

Williham Totland
  • 28,471
  • 6
  • 52
  • 68
  • Although JezenThomas makes some very excellent points, this is the only true *answer* to the *question*. – BoltClock Apr 27 '12 at 09:13
  • it might be the true answer, but as long as I asked such a question, it is clear that I am not that advanced in this subject. and this answer only puzzled me, with all the XHTML and XML and HTML. I just read something to find out what I am using, so it's " "...does this mean it is XHTML? then it means it is a bug? so, as you see, this much I understood of this answer :) the one above at least gave me something I could cope with – bokkie Apr 27 '12 at 09:40
  • @bokkie: The !DOCTYPE doesn't matter, because XML doesn't care, and in HTML it's gotten to the point where it's fundamentally meaningless. The only thing that matters is the content-type of the document as it is sent from server to browser: if it's `application/*xml`, absolutely all elements are valid for self-closure; if it's `text/html`, then only the silly ones are (br, hr, meta, link and img). – Williham Totland Apr 27 '12 at 09:45
  • @WillihamTotland: thanks, this was now much clearer :) the only thing is I don't know where to check wheter it is application/*xml or text/html :) – bokkie Apr 27 '12 at 09:52
  • @bokkie: Did you at any point tell the server that you wanted it served as XML? If not, it's text/html. – Williham Totland Apr 27 '12 at 09:56
  • @bokkie: Note also that "application/*xml" is shorthand for "application/svg+xml", or "application/xml", or "application/xhtml+xml", or any number of other document types. The correct one of these to use is always "application/xml". – Williham Totland Apr 27 '12 at 09:58
  • @WillihamTotland: I am working on an asp project with other 2 who at the moment are not here. I didn't do that, cause I wouldn't have known I have to do that, maybe one of the other two did (the TL?)...anyway... I looked in the masterpage and in the webconfig and it is not there – bokkie Apr 27 '12 at 09:59
1

Well, although this is valid XHTML, it's not valid HTML 4.*.

Simple as that...

Dr.Kameleon
  • 22,532
  • 20
  • 115
  • 223
0

Because is a tag container, even if it can be fill in javascript

--> http://www.w3.org/TR/html401/struct/global.html#h-7.5.4

ke20
  • 665
  • 4
  • 19