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.
Asked
Active
Viewed 123 times
0

Bhojendra Rauniyar
- 83,432
- 35
- 168
- 231
-
1possible 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
-
2FYI 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 Answers
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:

Community
- 1
- 1

Stefan Surkamp
- 972
- 1
- 16
- 31
-
vertical-align is not working ,, i mean height is not working. – Bhojendra Rauniyar Jul 18 '13 at 10:36
-
Why not? How is the fiddle looking in your browser? Which browser do you use? – Stefan Surkamp Jul 18 '13 at 10:37