MK-DK
MK-DK

Reputation: 1085

Setting same height on columns

I am making a row with 2 columns with Bootstrap 3. I am programming for a webshop there is having around 100.000 products, so it is not converted to BS4 yet. Therefore I am forced to use BS3. The left column is gonna contain a background color and some text, while the right column will be an image.

This is how the row is looking like now:

  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<div class="wrapper">
    <div class="row">
        <div class="col-sm-3" style="background-color:pink;">
            <h3>Headline</h3>
            <p>Some text here</p>
            <button type="button" class="btn btn-info">Button</button>
        </div>
        <div class="col-sm-9">
            <img src="http://placehold.it/900x200">
        </div>
    </div>
</div>

This is how my end result should be: enter image description here

Upvotes: 0

Views: 53

Answers (1)

M.A Shahbazi
M.A Shahbazi

Reputation: 1071

As said in comments your code is working, since you are using bootstrap 3 you may want to use img-responsive class for your image, because it has a large width.

By the way I have changed your col-sm-3 and col-sm-9 classes to xs ones, you may want to consider changing them to md or sm for your case.

<!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/3.4.1/css/bootstrap.min.css"
      integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu"
      crossorigin="anonymous"
    />
    <title>Static Template</title>
    <style>
      .d-flex {
        display: flex;
      }
      .image-container {
        background-size: cover;
        background-position: center center;
      }
    </style>
  </head>
  <body>
    <h1>
      This is a static template, there is no bundler or bundling involved!
    </h1>
  </body>
  <!-- Latest compiled and minified CSS -->
  <div class="container">
    <div class="wrapper">
      <div class="row d-flex">
        <div class="col-xs-3" style="background-color:pink;">
          <h3>Headline</h3>
          <p>Some text here</p>
          <button type="button" class="btn btn-info">Button</button>
        </div>
        <div
          class="col-xs-9 image-container"
          style="background-image: url(https://picsum.photos/id/287/900/200)"
        ></div>
      </div>
    </div>
  </div>

  <!-- Latest compiled and minified JavaScript -->
</html>

-Edit: after taking a deeper look on what you really want to achieve (same height for both columns) I updated my question with the follow:
Adding a class called d-flex to set a display: flex on any container you need, once a container has a display: flex; value its children will stretch by default.
You may also need to update your image to support a height: 100% which I highly recommend not to, cause it will make the image look ugly. Instead take advantage of background-size: cover;.

Some good resources on how to make your image fit in nicely:
https://css-tricks.com/almanac/properties/o/object-fit/
https://css-tricks.com/almanac/properties/b/background-size/

Upvotes: 1

Related Questions