Make DIV max-height equal to `window height - 100px`

后端 未结 2 552
终归单人心
终归单人心 2021-02-04 00:32

There is a way to set max-height in %, but is here any way to set DIV max-height, so it would be 100px smaller than window height with only CSS?

相关标签:
2条回答
  • 2021-02-04 00:51

    Yes:

    #specificElement {
        height: calc(100vh - 100px);
        box-sizing: border-box;
    }
    

    This uses the CSS calc() function to subtract 100px from 100vh (1vh being one percent of the view-port's height) and uses the result as the value of the height property.

    The box-sizing forces the browser to include padding, and borders, in the calculated height of the element.

    Obviously use a relevant selector for your use-case.

    References:

    • calc().
    • CSS lengths.
    0 讨论(0)
  • 2021-02-04 01:11

    #specificElement { height: calc(100vh - 100%); min-height: calc(100vh - 100px); }

    set min height so that your dyanmic content should not get effect and give height in percentage for dymanic result.

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