简体   繁体   English

为什么身高:calc(100% - 100px)不起作用

[英]why height: calc(100% - 100px) is not working

JsFiddle I am trying to set height of the test div as calc(100%-100px). JsFiddle我试图将测试div的高度设置为calc(100%-100px)。 why it is not working. 为什么它不起作用。

.test {
  height: calc(100%-100px);
 }

The operators + and - require whitespace before and after. 运算符+-需要前后的空格。 Try calc(100% - 100px). 尝试calc(100% - 100px). With the * operator you don't need whitespace ex. 使用*运算符,您不需要前面的空格。 calc(100%(1/15))

you can use 100vh instead 100%. 你可以使用100vh而不是100%。 vh = 1% of the height of the viewport. vh =视口高度的1%。

.test {
  height: calc(100vh - 100px);
}

Why are there multiple height css styles for #wrap ? 为什么#wrap有多种height css样式?

Try taking off height: auto !important; 尝试起飞height: auto !important;

http://jsfiddle.net/UaYfW/53/ http://jsfiddle.net/UaYfW/53/

below code will help you to fix the height the div .div{height: calc(100% - (20px + 30px));} working code as below : 下面的代码将帮助您修复div的高度.div {height:calc(100% - (20px + 30px));}工作代码如下:

html,body {
    background: blue;
    height:100%;
    padding:0;
    margin:0;
}
header {
    background: red;
    height: 20px;
    width:100%
}
h1 {
    font-size:1.2em;
    margin:0;
    padding:0;
    height: 30px;
    font-weight: bold;
    background:yellow
}
#theCalcDiv {
    background:green;
    height: -moz-calc(100% - (20px + 30px));
    height: -webkit-calc(100% - (20px + 30px));
    height: calc(100% - (20px + 30px));
    display:block
}

html code : HTML代码:

<header>Some nav stuff here</header>

<h1>This is the heading</h1>

<div id="theCalcDiv">This blocks needs to have a CSS calc() height of 100% - the height of the other elements.</div>

Working Example : http://jsfiddle.net/UF3mb/603/ 工作示例: http//jsfiddle.net/UF3mb/603/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM