簡體   English   中英

如何使引導卡停留在reactjs的屏幕中間

[英]How to get bootstrap card to stay in the middle of the screen in reactjs

我試圖讓卡停留在屏幕中間,但無法正常工作。 我使用了align-items和justify-content。 我看過不同的網站。

//Login.js

import React, { Component } from 'react';
import './App.css';

class Login extends Component {
  render() {
    return (
      <div className="App">
        <div className="card cardalign w-50">
          <div className="card-body">
          <img className="logo" src="https://cdn.macrumors.com/article-new/2018/05/apple-music-note-800x420.jpg"/>
                <h1 className="signintext">MusicFlo Signin</h1>
                <form className="logininputs">
                <input className="emailinput" placeholder="Email"/>
                <input className="passwordinput" placeholder="Password"/>
                <button className="btn btn-primary btn-md m-2">Log In</button>
            </form>
          </div>
        </div>
      </div>
    );
  }
}

export default Login;

和下面的CSS

//App.css

.App {
  text-align: center;
}

.App-logo {
  animation: App-logo-spin infinite 20s linear;
  height: 40vmin;
  pointer-events: none;
}

.App-header {
  background-color: #282c34;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: calc(10px + 2vmin);
  color: white;
}

.App-link {
  color: #61dafb;
}

.logo {
  height:120px;
  width: 220px;
  border-radius: 50%;
  margin-top: 150px
}

.signintext {
  margin-top: 50px;
  font-style: italic
}

.logininputs {
  display:flex;
  flex-direction: column;
  align-items: center
}

.emailinput {
  width: 30vw;
  height: 5vh;
  margin-bottom: 10px;
  border: solid 2px indigo
}

.passwordinput {
  width: 30vw;
  height: 5vh;
  border: solid 2px indigo
}

.card {
  align-items: center;
  justify-content: center;
  background-color: lightgrey;
  border: 5px solid black

}
@keyframes App-logo-spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

我瀏覽了reactjs紀錄片。 它仍然沒有顯示在中心。 請看圖片。 謝謝

在此處輸入圖片說明

任何信息都很好

這些家伙:

  align-items: center;
  justify-content: center;

僅在與display: flex結合設置時才能工作。

此外,它們僅在伸縮容器的容器上起作用,因此我認為制作伸縮容器的卡不起作用(假設這是需要居中的card )。 因此,應具有以下設置的是card父代

display: flex;
align-items: center;
justify-content: center;
width: 100%; // make sure the parent is full screen 
height: 100%; // so that the content will center correctly

將此添加到App CSS類

margin-left: auto;
margin-right: auto;

中心div

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM