Making a div fit the initial screen

后端 未结 10 979
谎友^
谎友^ 2020-12-04 17:49

I want to make a div fit the initial height and width of a users screen.

I think the following crudely drawn diagram explain this better:

10条回答
  •  不知归路
    2020-12-04 18:45

    Personally I like the pure CSS solution. Just use the vh unit.

    #filldiv
    {
        height: 100vh;
    }
    

    That will make the div fill the height of the browser window.

    In addition, you can also make it fill the width of the browser window, this only uses the vw unit.

    #filldiv
    {
        width: 100vw;
    }
    

    Both are shown in this fiddle

    I personally really like both of these units because they can be used for dynamic resizing of things such as font sizes.

提交回复
热议问题