图像左侧是文字

时间:2018-02-13 13:50:13

标签: html css3 layout bootstrap-4

我有一个问题是让图像显示在另一个带文字的div的左侧。

在某个断点之后,我希望图像悬挂在文本的左侧,我尝试了一些像浮动的东西:左边,试着玩弄显示器:块等但它根本不会让步。

我的确切断点是768px以下,然后图像必须堆叠在文本的左边,最大宽度为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>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

有几种不同的方法可以解决它。一种方法是在每个col-*-4内嵌套另一个2列网格。断点和宽度取决于你..

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;
    }
}