col-md-4 div中的图像不是全宽

时间:2016-04-25 11:24:33

标签: html css twitter-bootstrap

我想在col-md-4 div中创建一个全宽的图像。我尝试过使用img-responsive类以及宽度:100%但仍然无效。下面是我的HTML代码和css

HTML

<div class="col-lg-3 col-md-3 col-sm-3 col-xs-12 travelinfo">

  <h3>travel info</h3>
  <div class="col-md-4 smallImg">
    <img src="img/pokhara.jpeg" class="img-responsive">
  </div>
  <div class="col-md-8 NewsInfo">
    <a href="">The six best trekking routes </a>
    <p> March 22,2012</p>
  </div><div class="clear-fix"></div><br>



  <div class="col-md-4 smallImg">
    <img src="img/illam.jpeg" class="img-responsive">
  </div>
  <div class="col-md-8 NewsInfo">
    <a href="">amazing places </a>
    <p>may 30,2011</p>
  </div><div class="clear-fix"></div><br>


  <div class="col-md-4 smallImg">
    <img src="img/langtang.jpeg" class="img-responsive">
  </div>
  <div class="col-md-8 NewsInfo">
    <a href="">amazing langtang and gosaikund</a>
    <p>april 2015</p>
  </div><div class="clear-fix"></div>

</div>

CSS

.travelinfo .smallImg img{margin-top:25px;float: left;max-width: 100%;vertical-align: middle;}
.NewsInfo{float: right;line-height: 15px;margin-top: 20px;}

.NewsInfo a{font-family: 'Open Sans', sans-serif; font-size: 13px;color:#fff; text-transform:uppercase;font-weight: 400;}
.NewsInfo p{font-family: 'Open Sans', sans-serif; font-size: 13px;color:#ff590b; text-transform:uppercase;}

2 个答案:

答案 0 :(得分:0)

您可以使用此css代码在col-md-4 div。

范围内使图像全宽
 .smallImg img{width:100%}

答案 1 :(得分:0)

<div class="col-md-4 smallImg">
    <img src="img/langtang.jpeg" class="img-responsive" alt="">
</div>

不要错过alt=""以获得更好的练习。

CSS:

.smallImg img
{
    width:100%;
}