首页 > 解决方案 > 如何强制一行及其列使用​​其父元素高度的 100% (jumbotron)

问题描述

这就是我所拥有和想要的

所以我想将标语垂直和水平对齐到jumbotron,顶部标志在正确的位置,小同型应该一直在jumbotron的底部。

任何帮助是极大的赞赏。

#hero {
    height: 50vh;
    background-image: url("/img/background.png");
    background-size: cover;
    background-repeat: no-repeat;
    padding-top: 0.5em;
    padding-bottom: 0.5em;
}
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4"
        crossorigin="anonymous">
    <link rel="stylesheet" href="/css/custom.css">
    <title>Document</title>
</head>

<body>
    <div class="jumbotron jumbotron-fluid" id="hero">
        <div class="container">
            <div class="row">
                <div class="col-12 text-left align-top h-25">
                    <img src="/img/toplogo.png" alt="">
                </div>
                <div class="col-12 text-center align-middle h-auto">
                    <img src="img/slogan.png" alt="">
                </div>
                <div class="col-12 text-right align-bottom test">
                    <img src="/img/logowhite.png" alt="">
                </div>
            </div>
        </div>
    </div>
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
        crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js" integrity="sha384-cs/chFZiN24E4KMATLdqdvsezGxaGsi4hLGOzlXwp5UZB1LY//20VyM2taTB4QvJ"
        crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js" integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm"
        crossorigin="anonymous"></script>
</body>

</html>

标签: htmlcsstwitter-bootstrapbootstrap-4

解决方案


如果我是正确的,您要求将标语垂直对齐中心并将同种型对齐到底部,如上图所示。您可以将以下内联样式部分添加到口号和小同型。

将标语对齐到中间:

<img src="img/slogan.png" alt="" style="top:--height from the top-- ;">

或者

<img src="img/slogan.png" alt="" style="display: flex; flex-direction: column; justify-content: center;">

要将小同型设置为底部:

<img src="/img/logowhite.png" alt="" style="top:--height from the top-- ;">

或者

<img src="img/logowhite.png" alt="" style="display: flex; flex-direction: column; justify-content: center;">

我想,这对你有用。


推荐阅读