【问题标题】:How to center "Avatar" material UI component inside div? Ussing ReactJS and material UI如何在 div 中居中“头像”材质 UI 组件?使用 ReactJS 和材质 UI
【发布时间】:2021-08-09 18:22:50
【问题描述】:

我试图在我的项目中将头像材质 ui 组件居中,我尝试了很多东西,包括文本对齐、对齐内容、自动边距,但似乎没有任何效果。任何帮助将不胜感激

/////profile.js///////

 <div className="myProfile__outterContainer">
      <div className="myProfile__innerContainer">
        <div className="myProfile__header">
          <h2>My Profile</h2>
          <Avatar
            alt={user.displayName}
            src={user.photoURL}
            className={classes.large}
          />
          <h2>Welcome, {user.displayName}</h2>
        </div>
      </div>
    </div>

 
////// profile .css below
profile.css

    .myProfile__outterContainer {
  display: flex;
  justify-content: center;
  margin-top: 5vh;
}

.myProfile__innerContainer {
  position: relative;
  width: 800px;
  padding: 20px;
  max-width: 85vw;
  height: 75vh;
  border-radius: 20px;
  background-size: cover;
  background-position: center;
  box-shadow: 0px 18px 53px 0px rgba(0, 0, 0, 0.3);
}
.myProfile__header {
  text-align: center;
  justify-content: center;
  
}

【问题讨论】:

    标签: javascript css reactjs material-ui


    【解决方案1】:

    &lt;h2&gt; 标签和头像垂直居中:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-28
      • 2020-10-18
      • 1970-01-01
      • 2022-01-14
      • 2020-10-06
      • 2021-11-10
      • 1970-01-01
      • 2021-12-17
      相关资源
      最近更新 更多