【问题标题】:Elements are stuck in top left corner React/CSS元素卡在左上角 React/CSS
【发布时间】:2021-06-06 21:27:08
【问题描述】:

我正在使用 create-react-app 构建一个简单的反应页面,但布局有问题。我的组件嵌套在App中,仅限于页面顶部。

这是一张图片,显示了元素的位置和我的组件树:

// 应用程序

html, body {
  margin: 0;
  padding:0;
}

//容器

html, body {
    margin:0;
    padding:0;
  }

//标题

.loan-header {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    background: white;
    width: 100%;
    border: 0;
    border-radius: 3;
    box-shadow: 0 3px 5px 2px rgba(180, 180, 180, .3);
    color: white;
    height: 60px;
}

//应用容器


.loan-application-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: white;
    border: 0;
    border-radius: 3;
    box-shadow: 0 3px 5px 2px rgba(180, 180, 180, .3);
    color: #005350;
    height: 100px;
    width: 75%;
    top: 100px;
}

.applications {
    font-size: 12px;
    padding: 2;
    display: inline-flex;
    align-items: baseline;
    width: 100%;
    height: 50%;
    border: 0.32px;;
    border-radius:3;
    justify-content:space-between;
    font-size: 1vw;
    border-color: black;
}

.view-btn {
    height: 30;
    width: 10%;
    background: #005350;
    font-size: 1vw;
    color: white;
}

p {
    font-family: 'Gill Sans';
    font-weight: bold;
    font-size: 1vw;
    width: 30%;
    color: #005350;
}

https://imgur.com/a/SdRAq21

【问题讨论】:

  • 你使用弹性盒子吗? display: block?向您发布与您的元素相关的 CSS...
  • 添加了 CSS @zergski
  • @zergski 非常感谢。确实让它到达了顶部的中心。还有一个问题,我如何将那张申请卡放在中心,我似乎无法将它与标题分开。
  • 别担心,乐于助人!如果您接受我的回答,我将不胜感激。 =) 你的意思是垂直居中相同的元素吗?您在上一个问题中使用了什么解决方案?
  • 我使用了快速修复——我正在制作一个页面,其中两个“应用程序卡”位于页面中心。

标签: javascript css reactjs user-interface frontend


【解决方案1】:

您的.loan-application-container 的宽度为75%。 有多种方法可以解决这个问题。使用 flexbox,根据 flex-direction 属性,您可以在父级中指定 justify-content: centeralign-items: center 或在其自身中指定 justify-self: centeralign-self: center

或者作为快速修复尝试在.loan-application-container 规则集中尝试left: 0; right: 0; margin: 0 auto;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-11
    • 2013-09-12
    • 1970-01-01
    • 1970-01-01
    • 2021-01-03
    • 1970-01-01
    • 2018-12-18
    • 2018-08-12
    相关资源
    最近更新 更多