CSS height 100% percent not working [duplicate]

I have a div with height: 100%; but it's not working. When I declare a fixed height (for example height: 600px;) it is working, but I would like a responsive design.

html:

<blink><div> <div> <div> <ul> <li><a href="#html">Html</a></li> <li><a href="#helpers">Helpers</a></li> </ul> <div> <div> <textarea>{{:html}}</textarea> </div> <div> <textarea>{{:helpers}}</textarea> </div> </div> </div> </div> <div></div> <div> <div> <ul> <li> <a href="#">Preview <img width="22px" height="16px" src="img/spinner-green2.gif" /> </a> </li> </ul> <div> <div> <iframe name="previewFrame" frameborder="0" allowtransparency="true" allowfullscreen="true"></iframe> </div> </div> </div> </div> </div> </blink> 
2

7 Answers

You probably need to declare the code below for height:100% to work for your divs

html, body {margin:0;padding:0;height:100%;} 

fiddle:

1

You aren't specifying the "height" of your html. When you're assigning a percentage in an element (i.e. divs) the css compiler needs to know the size of the parent element. If you don't assign that, you should see divs without height.

The most common solution is to set the following property in css:

html{ height: 100%; margin: 0; padding: 0; } 

You are saying to the html tag (html is the parent of all the html elements) "Take all the height in the HTML document"

I hope I helped you. Cheers

1

I would say you have two options:

  1. to get all parent divs styled with 100% height (including body and html)

  2. to use absolute positioning for one of the parent divs (for example #content) and then all child divs set to height 100%

1

Set the containing element/div to a height. Otherwise your asking the browser to set the height to 100% of an unknown value and it can't.

More info here:

1

I believe you need to make sure that all the container div tags above the 100% height div also has 100% height set on them including the body tag and html.

For code mirror divs refer to the manual, these sections might be useful to you:

var editor = CodeMirror.fromTextArea(document.getElementById("code"), { lineNumbers: true, theme: "night", extraKeys: { "F11": function(cm) { cm.setOption("fullScreen", !cm.getOption("fullScreen")); }, "Esc": function(cm) { if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false); } } }); 

And also take a look at:

Also a comment:

Inline styling is horrible you should avoid this at all costs, not only will it confuse you, it's poor practice.

Night's answer is correct

 html, body {margin:0;padding:0;height:100%;} 

Also check that your div or element is NOT inside another one (with height less than 100%) Hope this helps someone else.

1

You Might Also Like