【问题标题】:Why isn't my image aligning to the bottom of my grid column?为什么我的图像没有与网格列的底部对齐?
【发布时间】:2019-02-13 15:04:50
【问题描述】:

我正在尝试设置一个网格系统,其中一侧是表格,另一侧是图像。现在的问题是我希望一切都到视口的底部,但由于某种原因,图像没有到屏幕的底部。

我已经尝试在body, * 和图像本身上添加height: 100vh,但它没有改变。

.login-section {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  grid-template-areas: "form form form form form form form form map map map map";
  align-items: center;
  justify-items: center;
}

.login-section .login-form {
  grid-area: form;
}

.login-section .login-map {
  grid-area: map;
  width: 100%;
  overflow-x: hidden;
}
<div class="login-section">
  <div class="login-map">
    <img src="../img/map.png" alt="photo map">
  </div>
  <div class="login-form">
    <div class="login-form-back">
      Bla bla login
    </div>
  </div>
</div>

【问题讨论】:

    标签: html css alignment css-grid


    【解决方案1】:

    login-section 提供height: 100vh 并使用align-items: flex-end - 请参见下面的演示:

    body {
      margin: 0; /* Reset body-margin */
    }
    img {
      display: block; /* Remove whitespace below image*/
      height: 100%; /* Image extending the full height of the grid item */
    }
    
    .login-section {
        display: grid;
        grid-template-columns: repeat(12, 1fr);
        grid-template-areas: "form form form form form form form form map map map map";
        /*align-items: center;*/
        align-items: flex-end; /* ADDED */
        height: 100vh; /* ADDED */
        justify-items: center;
    }
    
    .login-section .login-form {
        grid-area: form;
    }
    
    .login-section .login-map {
        grid-area: map;
        width: 100%;
        overflow-x: hidden;
        height: 100vh; /* image over full viewport*/
    }
    <div class="login-section">
            <div class="login-map">
                <img src="https://via.placeholder.com/100" alt="photo map">
            </div>
            <div class="login-form">
                <div class="login-form-back">
                    Bla bla login
                </div>
            </div>
        </div>

    【讨论】:

    • 它只是把所有东西都往下推,现在有一个滚动和图像上方的空白
    • @TristanVermeesch 查看编辑后的答案,如果现在看起来不错,请告诉我...
    • 这仍然不起作用,如果现在调整大小,它会超出网格范围
    • 那么图片应该从屏幕的顶部延伸到底部?
    • 是的,它应该占据整个高度
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-21
    • 2018-05-24
    • 2021-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多