代码之家  ›  专栏  ›  技术社区  ›  Enoy

如何使web内容的宽度和高度与窗口的宽度和高度相适应

  •  -2
  • Enoy  · 技术社区  · 6 年前

    目前在封面和场景页面都有垂直滚动条。

    enter image description here

    封面图片有自己的css类封面图片:

    .coverImage {
        display: block;
        margin-left: auto;
        margin-right: auto;
        width: 100%;
    }
    

    此外,内部场景页面具有相同的行为,它显示一个垂直滚动条: enter image description here

    .miniature {
        width: 100px;
        height: 100px;
        margin: 10px;
    }
    
    .nrrdCanvas {
        margin: 25px 25px;
    }
    

    我也读过:

    https://developers.google.com/web/fundamentals/design-and-ux/responsive/

    Set size of HTML page and browser window

    1 回复  |  直到 6 年前
        1
  •  1
  •   StefanBob    6 年前

    没有代码,我可以给你一般的建议。如果希望页面上的某个元素跨越窗口的整个高度和宽度,一种方法是使用视口单位设置其宽度和高度。

    .element {
       width: 100vw;
       height 100vh;
    }
    

    .other-element {
       width: 20%;
    }
    

    另外一个非常有用的响应和布局的工具是flexbox。https://css-tricks.com/snippets/css/a-guide-to-flexbox/