简体   繁体   中英

White space left and right around images when using bootstrap col

I have a row with 3 images.
Image left has white space on the left side.
Image right has white space on the right side.

How can I fix this so I don't have any with space on the left and right side?

See my code below:

The background is orange in the image so it's better visible.

HTML:

<div class="container section">
  <div class="row">
    <div class="col-md-offset-1 col-md-10 featured">

      <div class="col-md-4 img-featured-1">
        <%= image_tag("featured-1.jpeg", class: "img-responsive") %>
      </div>
      <div class="col-md-4 img-featured-2">
        <%= image_tag("featured-2.jpeg", class: "img-responsive") %>
      </div>
      <div class="col-md-4 img-featured-3">
        <%= image_tag("featured-3.jpeg", class: "img-responsive") %>
      </div>

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

CSS:

.featured {
  background-color: orange;
}
.img-featured-1 {
  width: 33.33333%;
  float: left;
}
.img-featured-2 {
  width: 33.33333%;
}
.img-featured-3 {
  width: 33.33333%;
  float: right;
}

See the image

Try this:

.featured {
  background-color: orange;
}

 .nopadding {
  padding:15px 0px;}

+

<div class="container section">
  <div class="row">
    <div class="col-md-offset-1 col-md-10 nopadding">

      <div class="col-md-4 img-featured-1">
        <img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97150&w=350&h=150">
      </div>
      <div class="col-md-4 img-featured-2">
        <img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97150&w=350&h=150">
      </div>
      <div class="col-md-4 img-featured-3">
        <img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97150&w=350&h=150">
      </div>

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

It's probably because the .row class is adding some margin on the sides.

Try this:

.row {
   margin: 0;
 }

Couple things, first thing is your style sheet. It should be .img-featured-1 (the dot defines this style applies to classes of the given name).

Next, if that doesn't resolve, check your themes style sheet and or override the margin and padding with { margin: 0 !important; padding: 0 !important; }

Finally, make sure your images themselves don't have white / transparent space.

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