【问题标题】:Using calc() during calculate height在计算高度期间使用 calc()
【发布时间】:2014-03-08 01:34:20
【问题描述】:

我编程非常简单的布局。 它由 5 个 div -> http://jsfiddle.net/8tSk6/ 组成。 我希望 ID 为“kubka”的 div 等于 100% - 100px (height: calc(100% - 100px);)。不幸的是,它不起作用。 我尝试使用 CSS3 height: calc(100%) not working 应用提示(添加高度 = 100%,边距和填充 = 0),但脚本仍然不起作用。

【问题讨论】:

  • 但是高度是什么元素的 100%?父 www 没有高度

标签: html css height css-calc


【解决方案1】:

1) 你需要添加html {height:100%;}

2) 删除您的 div 和 # 之间的空格 - 您的样式意味着在 div 中找到的任何内容的 id,如果您查看您的 www div,它不在任何其他 div 中

如果你把这些整理出来,我认为它会起作用:fiddle

【讨论】:

    【解决方案2】:

    您可以使用 javascript 获取元素的高度,然后更改它:

    function updateHeight(divId){
        var urDiv = document.getElementById(divId);
        urDiv.height = window.innerHeight - 100;
        urDiv.style.height = urDiv.height + "px";
    }
    

    希望它能解决你的问题。

    【讨论】:

      猜你喜欢
      • 2021-07-03
      • 2017-05-30
      • 2016-08-30
      • 2017-11-28
      • 2018-07-10
      • 2016-01-23
      • 2018-10-21
      • 1970-01-01
      • 2014-10-08
      相关资源
      最近更新 更多