简体   繁体   中英

Why does my image go outside of the bootstrap grid?

I have created a 3 column grid which contains some text and an image in between using Bootstrap 4 for the grid system.

I've noticed that although my image has a img-fluid class assigned the image overflows outside the div.

Can anyone explain the reason for this?

HTML

  <div class="row">
    <div class="col blue-bg-outter">
      <div class="col blue-bg" style="height: 300px;">

        <!-- start of content -->
        <div class="row">
          <div class="col">
            <h2> Some line</h2>
          </div>
          <div class="col img-col">
            <img src="https://purepng.com/public/uploads/large/51508089516arw4tqfangou1wmvwzihlw7hxnzjujpulweq1otwrsdcsaxc5kvmu1crkpcyfxezyx4dmcvkbgg5w7oc1sioxib4j044tjwbfcyu.png" alt="" class="img-fluid">
          </div>
          <div class="col">
            <h2> Another line</h2>
          </div>
        </div>

      </div>
    </div>
  </div>

CSS

.img-fluid {
  max-height: 100vh;
}

.blue-bg-outter { 
  padding: 60px;
}

.blue-bg { 
  background: #3ad7f7;
}

Might be easier to see on an actual page, please view the CodePen .

Because you have set a height on a parent div to 300px , if you remove height it works. Or you can set the height of img-fluid to 300px as @august suggested:

<div class="col blue-bg">

https://codepen.io/anon/pen/oJKvLp

Or you can keep the height and stop the image overflowing like this:

.blue-bg
{
    overflow: hidden;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM