0

I have 3 Div-Container inside a row. Each one has, caused by the content, a different height. I want to set background color, but the color should reach to the bottom of the parent-Div (Row). All my tries failed, I wont get the same height of the divs.

<div class="row">
  <div class="col-md-7">Test</test>
  <div class="col-md-2">Test</test>
  <div class="col-md-3">Test</test>
</div>

With a table it will be easy, but thats not the state of the art...

What will be the css-style for do that, if I wont to support responsive layout?

Shidersz
  • 16,846
  • 2
  • 23
  • 48
StefB
  • 81
  • 1
  • 11
  • What version of Bootstrap you are using? The approach for this will be setting a fixed height to the `row` and then `100%` height for all the `col` children. **Bootstrap 4** have some utilities classes for this... If you specify the Bootstrap version I will show you an example. – Shidersz Dec 14 '18 at 21:43
  • currently 3 , i think about 4 – StefB Dec 14 '18 at 21:45
  • adding a fix height, is not so pretty, if i have smaler devices, i lost unused space in same divs. – StefB Dec 14 '18 at 21:46
  • You could apply the rules only on medium or large devices using a `media query` in that case. I will come with an example later if you still accept having a fixed height on the `row` for **md** screens and above. – Shidersz Dec 14 '18 at 21:49
  • year setup for different devices will be a way to do i think :-) – StefB Dec 14 '18 at 21:57

1 Answers1

1

For Bootstrap 3 versions, you could approach a fixed height for md+ screen devices (width >= 992px) with something like this:

@media(min-width:992px) {

    .fixed-md-height {
        height: 150px;
    }
    
    .h-100 {
        height: 100%;
    }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

<div class="container-fluid">
  <div class="row fixed-md-height">
    <div class="col-md-7 h-100 bg-danger">Test</div>
    <div class="col-md-2 h-100 bg-primary">Test</div>
    <div class="col-md-3 h-100 bg-warning">Test</div>
  </div>
</div>

On Bootsrap 4 there already exists a built-in class h-100, but the md breakpoint changes to width >= 768px. So the approach will be something like this:

@media(min-width:768px) {

    .fixed-md-height {
        height: 150px;
    }
}
<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.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>

<div class="container-fluid">
  <div class="row fixed-md-height">
    <div class="col-md-7 h-100 bg-danger">Test</div>
    <div class="col-md-2 h-100 bg-primary">Test</div>
    <div class="col-md-3 h-100 bg-warning">Test</div>
  </div>
</div>
Shidersz
  • 16,846
  • 2
  • 23
  • 48
  • @bootstrap3 have a define generaly height for .fixed-md-height and/or h-100? – StefB Dec 14 '18 at 22:35
  • For what I know, I will say no, but i'm not `100%` sure. Note that `fixed-md-height` is just a custom class I have made. So, do this approach work for your goals? – Shidersz Dec 14 '18 at 22:38