0

I wanted to use calc(100%-100px) which didn't work in my demo as the height is only accepting in pixels so how to convert this percentage value to pixels.

Bhojendra Rauniyar
  • 83,432
  • 35
  • 168
  • 231
  • 1
    possible duplicate of [CSS: expression ( use percentage & pixels to calculate )](http://stackoverflow.com/questions/4345047/css-expression-use-percentage-pixels-to-calculate) – Rory McCrossan Jul 18 '13 at 10:19
  • 2
    FYI put whitespaces before and after the -. Some browsers don't like it if you put it right behind the % and right before the second value. –  Jul 18 '13 at 10:27

2 Answers2

1

The following will give you height:

$(window).height();   // returns height of browser viewport
$(document).height(); // returns height of HTML document

To set the values

$(window).height(800);
$(document).height(800);

Or you could use good old Javascript

window.resizeTo(800, 600);

Here is the JSFiddle you asked for in comments.

Jay Patel
  • 657
  • 1
  • 6
  • 14
1

Give this a try:

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

div {
    height: calc(100% - 100px); /* IE9+ and future browsers */
    height: -moz-calc(100% - 100px); /* Firefox */
    height: -webkit-calc(100% - 100px); /* Chrome, Safari */
    vertical-align: middle;
    background-color: yellow;
}

p{
    background-color: red;
    padding: 20px;
}

Seems like table-cell doesn't allow calc(...)

See: http://jsfiddle.net/az4dB/3/

EDIT:

See this example, adapted from this awesome post:.

Community
  • 1
  • 1
Stefan Surkamp
  • 972
  • 1
  • 16
  • 31