English 中文(简体)
Is this syntatically valid for div?
原标题:
  • 时间:2009-11-17 12:27:33
  •  标签:
  • xhtml
<div class= clear ></div>

/*which comes out to be below one in FF (seen via firebug) */

<div class= clear />

/*is this the last empty div declaration is semantically valid ? */
最佳回答

According to the HTML 4.01 DTD <div /> is not valid.

问题回答

In XHTML, the construct is valid (and identically equivalent to your original source) but not HTML compatible.

HTML compatibility doesn t matter when it comes to viewing a representation of the DOM as seen by the browser. It does matter when writing markup.

As an aside, adding empty elements purely for styling purposes is ugly and should be avoided if possible. See http://www.ejeliot.com/blog/59 for some alternative methods for containing floats.

If you re asking if those two tags are equivalent and valid: yes, yes they are.

See this question for practical considerations.

Yes, why wouldn t it be?

Whether this is valid or not depends on the DOCTYPE of the document you are writing. I would suggest to get a definitive answer you try the here:

http://validator.w3.org/

<div class= clear ></div>

and

<div class= clear />

both are same. Though i prefer former one over the later.

A DIV is a block level container. The second example can t contain anything... so my bet would be no (for an HTML4 doctype)

If you want to use a dummy element for clearing purposes - have you considered <br />?

Edit

There are more effective ways of clearing than using using a block level container. Applying a clear class to <br /> is one example - but overflow: hidden on the parent element is usually much more elegant.





相关问题
Is this syntatically valid for div?

<div class= clear ></div> /*which comes out to be below one in FF (seen via firebug) */ <div class= clear /> /*is this the last empty div declaration is semantically valid ? */

How to apply pagination in IFrame

I have an IFrame with a Table enclosed within it. I want to display 15 rows of a table and than a Next button must be there to move forward. How to apply pagination for IFrame?

Scala and HTML parsing

How do you load an HTML DOM document into Scala? The XML singleton had errors when trying to load the xmlns tags. import java.net._ import java.io._ import scala.xml._ object NetParse { import ...

热门标签