开发者

Is this syntatically valid for div?

开发者 https://www.devze.com 2022-12-11 11:35 出处:网络
<开发者_高级运维div class=\'clear\'></div> /*which comes out to be below one in FF (seen via firebug) */
<开发者_高级运维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 ? */


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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消