Javascript 按百分比定位Div元素

Javascript 按百分比定位Div元素,javascript,css,Javascript,Css,我目前有一个html页面,需要创建一个div,它是页面的全宽。我正试图按照百分比而不是px来组织该职位的部门。问题是与div关联的类,该类需要整页 我的css代码如下所示: .question { position: absolute; min-height: 100%; min-width: 100%; } #titlepage{ position: relative; top: 30%;

我目前有一个html页面,需要创建一个div,它是页面的全宽。我正试图按照百分比而不是px来组织该职位的部门。问题是与div关联的类,该类需要整页

我的css代码如下所示:

.question {
        position: absolute;
        min-height: 100%;
        min-width: 100%;
      }

      #titlepage{
        position: relative;
        top: 30%;
        width: 50%;
        text-align: center;
        overflow: auto;
        margin-left: auto;
        margin-right: auto;
      }

      html, body {
        background-color: #A0B8C8;
        height:100%;
        width:100%;
      }

<body ontouchmove="BlockMove(event);">
      <div class="question">
        <div id="titlepage">
          <h1> test data </h1>
        </div>
      </div>
有人能解释为什么吗?

改变

top: 30%;


我希望这就是你要问的。

你也可以发布你的HTML吗?你也需要显示你的HTML。它似乎如您所描述的那样工作?因为这是CSS定位,所以javascript标记放错了位置。该示例确实起作用,但我的div容器相互之间,而不是一个接一个。我希望重新定位div,而不是缩放它。它的定位不是水平居中
top: 30%;
height: 30%