【问题标题】:Ionic flexbox cannot set input verticalIonic flexbox 无法设置垂直输入
【发布时间】:2019-04-12 23:55:15
【问题描述】:

我使用 flexbox 将我的按钮设置在页面中间。但无论我尝试什么,justify-content: center 都有效,但 align-items: center 会被忽略。

这是我的 HTML 代码:

<ion-content padding class="login">
  <div class="flex-container">
      <img src="assets/imgs/startbuttontext.png" class="flex-item" 
       style="height: 33vh;">
  </div>
</ion-content>

这里是我的 CSS:

.login {
    background: url(../assets/imgs/background1.png);
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center;
    margin: auto;
    z-index: 2;
    position: relative;


    .flex-container {
        display: flex !important;
        justify-content: center;
        align-items: center !important;

        .flex-item {
            padding:0 10px;
            display: flex;
            align-items: center !important;
            height: 33.3%;
        }
    }

}

【问题讨论】:

    标签: html css ionic-framework flexbox center


    【解决方案1】:

    您应该将高度设置为容器元素,而不是项目:

    .flex-container {
        height: 33vh;
    }
    

    【讨论】:

    • 另外,我会尽量避免使用!important,除非你使用 f.i. Bootstrap 可能有覆盖你的样式的讨厌习惯,除非你真的很具体。
    • 对,但这并不能改变问题。 !important 我刚试过,但没用
    • 使用您发布的代码,我的答案应该可以工作。如果没有,那么您的代码中还有其他冲突。尝试在您的浏览器开发工具中查找导致冲突的原因。
    猜你喜欢
    • 2018-08-01
    • 2019-07-06
    • 2018-10-05
    • 2016-12-04
    • 1970-01-01
    • 2014-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多