height: calc(100%) not working correctly in CSS

后端 未结 7 903
面向向阳花
面向向阳花 2020-12-02 15:09

I have a div that I want to fill the whole height of the body less a set number in pixels. But I can\'t get height: calc(100% - 50px) to work.

The reas

相关标签:
7条回答
  • 2020-12-02 16:06

    First off - check with Firebug(or what ever your preference is) whether the css property is being interpreted by the browser. Sometimes the tool used will give you the problem right there, so no more hunting.

    Second off - check compatibility: http://caniuse.com/#feat=calc

    And third - I ran into some problems a few hours ago and just resolved it. It's the smallest thing but it kept me busy for 30 minutes.

    Here's how my CSS looked

    #someElement {
        height:calc(100%-100px);
        height:-moz-calc(100%-100px);
        height:-webkit-calc(100%-100px);
    }
    

    Looks right doesn't it? WRONG Here's how it should look:

    #someElement {
        height:calc(100% - 100px);
        height:-moz-calc(100% - 100px);
        height:-webkit-calc(100% - 100px);
    }
    

    Looks the same right?

    Notice the spaces!!! Checked android browser, Firefox for android, Chrome for android, Chrome and Firefox for Windows and Internet Explorer 11. All of them ignored the CSS if there were no spaces.

    Hope this helps someone.

    0 讨论(0)
提交回复
热议问题