Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ReactJS-CSS Flexbox:我已经设置了一个Flexbox来对齐我的元素,但是我的页面无法垂直居中_Css_Reactjs_Flexbox - Fatal编程技术网

ReactJS-CSS Flexbox:我已经设置了一个Flexbox来对齐我的元素,但是我的页面无法垂直居中

ReactJS-CSS Flexbox:我已经设置了一个Flexbox来对齐我的元素,但是我的页面无法垂直居中,css,reactjs,flexbox,Css,Reactjs,Flexbox,我已设置flexbox以对齐元素,但我的页面无法垂直居中。 我不明白为什么,因为我的页面甚至有一个容器,所以我还必须确保视口单位的粗体大小。 所以这里是我的沙盒: 下面是我的代码片段: class App extends Component { state = { name: "", message: "", messageStock: [] } render() { return ( <div className={sty

我已设置flexbox以对齐元素,但我的页面无法垂直居中。 我不明白为什么,因为我的页面甚至有一个容器,所以我还必须确保视口单位的粗体大小。 所以这里是我的沙盒:

下面是我的代码片段:

class App extends Component {


  state = {
    name: "",
    message: "",

    messageStock: []
  } 

  render() {
    return (
      <div className={style.page}>
        <div className={style.page_container}> 

          <div className={style.form_container}>
            <form onSubmit={this.emitMessage} > 
              <input
                name="message"
                type="text"
                placeholder="message"
                value={this.state.message}
                onChange={this.handleChange}
              />
              <input type="submit" value="Send" />
            </form>
          </div>
          <div
            className={style.link}
          >
            <p>Go to&nbsp;</p>
            <div prefetch href="/">
              <a>/Home</a>
            </div>

            <br />

            <p>Go to&nbsp;</p>
            <div prefetch href="/letchat">
              <a>/Letchat</a>
            </div>
          </div>
        </div>
      </div>
    )
  }
}
任何暗示都很好,
感谢要垂直对齐内容,您需要在style.module.css中添加最后几行:


.page{
宽度:100vw;
身高:100%;
最小高度:100vh;
背景:rgb(219101255);
/*添加了以下内容*/
显示器:flex;
弯曲方向:立柱;
对齐项目:居中;
}

将上述规则添加到styles.modules.css文件中


Codesandbox链接:

当你说你的页面无法垂直对齐时,你是指滚动条吗?
.page{ 
    width: 100vw;
    height: 100%;
    min-height: 100vh; 
    background: rgb(219, 101, 255);  
}

.page_container{
      padding: 5vh 3vw;
}

.page .form_container{ 
    height: 100%;
    width: 100%;
    display:flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.page form{
    display:flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.page form input[type="text"]{ 
    height: 10vh;
    width: 30vw;
}
.message_box{ 
    background: white; 
    height: 40vh;
    width: 70vw;
    margin:auto;
    border:solid greenyellow; 
    margin-bottom: 5vh;
    overflow: scroll;
}

.message_item{ 
    margin: 2vh 0; 
}

.link{ 
    display:inline-block; 
}
.page{ 
    width: 100vw;
    height: 100%;
    min-height: 100vh; 
    background: rgb(219, 101, 255); 

    /*add following to center align content vertically */ 
    display:flex;
    align-items: center;/*vertically align page_container*/
    justify-content:center/*horizontally align page_container*/
}

.page_container{
      padding: 5vh 3vw;

      /* add following to center align content of page_container horizontally*/
      text-align:center
}