Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<doctype html> is messing up my CSS

In a nutshell, i want a right div float to extend vertically 100% but it only works when i don't include <doctype> on my html

in today's standard, do i really have to add <doctype>?

This is the result in Internet Explorer:

doctype issues

this is just simple html

<html>
<head>
<style type="text/css">
html, body {
padding:0;
margin:0;
height:100%;
}
#wrap {
background:red;
height:100%;
overflow:hidden;
}
#left {
background:yellow;
float:left;
width:70%;
min-height:100%;
}
#right {
background:pink;
float:right;
width:30%;
min-height:100%;
}
</style>

<body>
<div id="wrap">
<div id="left"> Content </div>
<div id="right"> Side Content </div>
</div>
</body>
</html>
like image 288
user1735120 Avatar asked Dec 13 '12 05:12

user1735120


People also ask

What happens if I delete DOCTYPE HTML?

The absence of the DOCTYPE or its incorrect usage will force the browser to switch to quirks mode. It means that the browser will do its best to layout the page that is considered to be old or created against web standards.

Do you need DOCTYPE for CSS?

Per HTML and XHTML standards, a DOCTYPE (short for “document type declaration”) informs the validator which version of (X)HTML you're using, and must appear at the very top of every web page. DOCTYPEs are a key component of compliant web pages: your markup and CSS won't validate without them.

What is DOCTYPE in CSS?

Doctype HTML is a declaration that tells the browser what version of HTML the document is written in. This declaration appears as the very first line in an HTML file.

Will HTML5 work if you do not put DOCTYPE HTML in your HTML file?

DOCTYPE html> // Tells the browser that we are using HTML5. If document type is not mentioned, browser will go to Quirks mode. Quirks mode depends upon the web browser version, If is older version then this will not support HTML5 tags (Example: header tag, footer tag, section tag,...)


2 Answers

in today's standard, do i really have to add <doctype>?

You don't have to do anything, but the absence of the DOCTYPE is essentially asserting that you conform (in the loosest sense of the term) to an unknown/inconsistent "quirks" standard.

I imagine the solution is as simple as setting the height of the parent container to 100% or to a specific pixel height.

  • ensure that height is set on the HTML and BODY elements.
  • ensure that height is set on any parent containers.

Working example: http://jsfiddle.net/7xxFj/

<div id="one">
    First column
</div>
<div id="two">
    second column
</div>​

HTML, BODY { height: 100%; }
#one { height: 100%; width: 30%; float: left; background-color: red; }
#two { height: 100%; width: 70%; float: left; background-color: blue; }

As @BoltClock pointed out in the comments, you probably want a layout that can extend beyond 100%. This requires a little more effort (but still works well within the standard).

This article shows several methods for accomplishing layouts with equal column heights. More methods here.

like image 146
Tim M. Avatar answered Oct 12 '22 03:10

Tim M.


If you are thinking of considering IE (any version for that matter, lets not digress to this topic), then you are better of specifying the DOCTYPE. I have seen many pages which do not do this properly through IE into the famous Quirks mode.

like image 31
Prasad Ajinkya Avatar answered Oct 12 '22 04:10

Prasad Ajinkya