Joost Hansworst
Joost Hansworst

Reputation: 53

Image left side of text

I have a problem with getting images to show up on the left side of another div with text.

After a certain breakpoint I would like the image to hang on the left side of the text, I tried some things like float: left, tried playing around with the display: block etc but it wont budge at all.

My exact breakpoint is anywhere under 768px then the images have to stack left of the text, max width 150px.

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

#mu-featured {
  position: relative;
  width: 100%;
  margin-top: 50px;
}

#mu-featured h2 {
  font-family: lato;
  font-size: 16px;
  font-weight: bold;
}

#mu-featured p {
  font-family: Roboto;
  font-size: 15px;
  color: #999;
}

.mu-featured-img img {
  width: 100%;
  height: auto;
  border-radius: 3px;
  margin-bottom: 25px;
}

.mu-featured-area {
  padding: 70px 0 50px;
  width: 100%;
}

@media (max-width: 767px) {
  .mu-featured-container {
    overflow: auto;
  }
  .mu-featured-img {
    float: left;
  }
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

<section id="mu-featured">
  <div class="container">
    <div class="row">

      <div class="col-xl-4 col-md-4 col-sm-12 mu-featured-container">
        <div class="mu-featured-img">
          <img src="https://static.pexels.com/photos/92623/pexels-photo-92623.jpeg" alt="">
        </div>
        <div class="mu-featured-content">
          <h2>TITLE</h2>
          <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. 
          </p>
        </div>
      </div>

      <div class="col-xl-4 col-md-4 col-sm-12 mu-featured-container">
        <div class="mu-featured-img">
          <img src="https://static.pexels.com/photos/92623/pexels-photo-92623.jpeg" alt="">
        </div>
        <div class="mu-featured-content">
          <h2>TITLE</h2>
          <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. 
          </p>
          <a href="#" class="">Call to action!</a>
        </div>
      </div>

      <div class="col-xl-4 col-md-4 col-sm-12 mu-featured-container">
        <div class="mu-featured-img">
          <img src="https://static.pexels.com/photos/92623/pexels-photo-92623.jpeg" alt="">
        </div>
        <div class="mu-featured-content">
          <h2>TITLE</h2>
          <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. 
          </p>
          <a href="#" class="">Call to action!</a>
        </div>
      </div>

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

Upvotes: 1

Views: 63

Answers (1)

Carol Skelly
Carol Skelly

Reputation: 362360

There are several different ways to solve it. One way is to nest another 2-column grid inside each col-*-4. The breakpoints and widths are up to you..

https://www.codeply.com/go/d8v0VbCaho

        <div class="col-md-4 col-sm-12 mu-featured-container">
                <div class="row no-gutters">
                    <div class="col-md-12 col-4 mu-featured-img pr-1">
                        <img src="https://static.pexels.com/photos/92623/pexels-photo-92623.jpeg" alt="">
                    </div>
                    <div class="col-md-12 col-8 mu-featured-content">
                        <h2>TITLE</h2>
                        <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
                        </p>
                    </div>
                </div>
        </div>

CSS for max 150px image...

@media (max-width: 767px) {
    .mu-featured-img img {
        max-width: 150px;
    }
}

Upvotes: 1

Related Questions