开发者

Which doctype do I need?

I'm having an issue using the default VS doctype of

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

On my page I have a content box, which contains two divs, one floated left and the other floated right. The right floated div contains a height: 100%, however, this is never applied to match the height of the left div.

When I remove the doctype (bad, I know, but was just testing..) in IE8 the site looks like a dogs breakfast, whereas in Chrome and Firefox it looked exactl开发者_开发百科y as I wanted it to.


You should use whatever doctype fits the version of HTML you have been coding for. e.g <!DOCTYPE HTML> for HTML 5.


No DOCTYPE basically means that browsers will assume broken HTML and will try to guess so you'll never get coherent results. Just pick any spec of your choice (I try to avoid XHTML but it's a matter of taste) and run your code through an HTML validator until it has no errors.


You should use a Doctype that:

  • Triggers standards mode (AKA strict mode)
  • Reflects the markup you are writing (which should usually be:)
    • HTML 4.01 Strict by default (or Transitional if you really need something from it)
    • HTML 5 if you are using features from the draft
    • XHTML 1.0 Strict (or Transitional if you really need something from it) if you have an XML toolchain with Appendix C normalisation at the end

The Doctype you have triggers standards mode, so you just need to figure out why browsers don't render content as you expect (there is a high chance that this will be due to errors in your CSS or markup that could be detected with a validator).


Not an answer: Search for two column layout.

Hint: search for "clear: both"-style solutions. (see http://www.quirksmode.org/css/clearing.html)


Are you looking for the two divs to be identical in height? That will never be the case in standards mode because divs don't behave in the same way that table cells do. Table cells stretch to meet the dimensions of the table, divs are independent containers and do not behave in the same manner.

However there are solutions such as the Faux Column technique.

Here's a an article on the "Faux Columns" technique.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜