So here I have a problem with Bootstrap 4 (and also flexbox). Here is the code: HTML:
<section id="intro">
<div class="container-fluid">
<div class="row align-items-center">
<div class="col align-self-center">
<h1>We design things</h1>
</div>
</div>
</div>
</section>
And CSS:
#intro {
min-height: 65vh;
background-image: url("../img/intro.png");
background-size: cover;
background-repeat: no-repeat;
background-position: center;
}
.container-fluid {
height: 100%;
min-height: 100%;
}
I want the .container-fluid to always be 100% of it's parent height, so if section has 100vh, container should also, if it has 50vh it also should have 50vh. How do I do that? I can't center something using flexbox if it's height is the height of h1.
You can also use max-width: 100%; and max-height: 100%; utilities as needed.
The .container class provides a responsive fixed width container. The .container-fluid class provides a full width container, spanning the entire width of the viewport.
You just have to use class="row-eq-height" with your class="row" to get equal height columns for previous bootstrap versions.
To set the width of an element to 75%, use the . w-75 class in Bootstrap.
In general, when you want an element to be the height of its parent, make the parent a flex container.
#intro {
min-height: 65vh;
background-image: url("../img/intro.png");
background-size: cover;
background-repeat: no-repeat;
background-position: center;
display: flex; /* NEW */
}
An initial setting of a flex container is align-items: stretch
. This means that the children of a flex container will automatically stretch the full cross-size of the container. In row-direction that would be the height. Hence, apply display: flex
or display: inline-flex
to section#intro
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With