krmax44 krmax44 - 6 months ago 19
CSS Question

Scale div with background image to remaining height

I have a Bootstrap page that looks like this:

<nav> ... </nav> <!-- height not fixed -->
<div class="container-fluid eye-catcher">
<div class="row">
<div class="col-sm-8"> ... </div>
<div class="col-sm-4 image"> ... </div>
</div>
</div>


In the end, it should look like this:
enter image description here

The code for the image I have is this, which works fine...

.image {
background-image: url("image.png");
background-size: contain;
background-position: center top;
background-repeat: no-repeat;
height: 100%;
}


...but how can I let the row filling up (only) the remaining space (no scrollbar should be visible then)

Answer

You can add some Flexbox with media queries. Full code HERE

.content {
  display: flex;
  flex-direction: column;
  height: 100vh;
}
nav {
  padding: 10px;
  border: 1px solid black;
}
.image {
  background: lightblue;
}
.left {
  background: lightgreen;
}
@media(min-width: 768px) {
  .eye-catcher {
    flex: 1;
    border: 1px solid black;
    display: flex;
    width: 100%;
  }
  .flex-row {
    display: flex;
    flex: 1;
  }
}