简体   繁体   English

Bootstrap img-responsive类 - 图像重叠

[英]Bootstrap img-responsive class - Images overlapping

I have two rows containing 3 images each. 我有两行,每行包含3张图片。 I am using the Bootstrap grid system. 我正在使用Bootstrap网格系统。 My problem is, is that the images on the second row run into the images in the top row. 我的问题是,第二行的图像是否会进入顶行的图像。 Here is my markup: 这是我的标记:

 @import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css'); .img-responsive { max-width: 100%; width: 100%; height: auto; display: block; } 
 <div class="container"> <div class="row"> <div class="col-md-4"><img src="https://s3.amazonaws.com/codecademy-content/projects/red-eye-photography/p1.jpg" class="img-responsive"></div> <div class="col-md-4"><img src="https://s3.amazonaws.com/codecademy-content/projects/red-eye-photography/p2.jpg" class="img-responsive"></div> <div class="col-md-4"><img src="https://s3.amazonaws.com/codecademy-content/projects/red-eye-photography/p3.jpg" class="img-responsive"></div> <div class="col-md-4"><img src="https://s3.amazonaws.com/codecademy-content/projects/red-eye-photography/p4.jpg" class="img-responsive"></div> <div class="col-md-4"><img src="https://s3.amazonaws.com/codecademy-content/projects/red-eye-photography/p5.jpg" class="img-responsive"></div> <div class="col-md-4"><img src="https://s3.amazonaws.com/codecademy-content/projects/red-eye-photography/p6.jpg" class="img-responsive"></div> </div> </div> 

I apologize if this question has already been answered. 如果这个问题已经得到解答,我道歉。 I'm a total newb, hoping not to be a newb for long. 我是一个全新的人,希望不要长久成为新手。 Thank you! 谢谢!

UPD . UPD I want to have the two rows separated so there's a thin space between them. 我希望将两行分开,以便它们之间有一个很小的空间。

I am no expert when it comes to html, but wouldn't an easy solution be to just add some breaks under the first row? 在html方面我不是专家,但是在第一行下添加一些中断不是一个简单的解决方案吗?

It would look something like this... 看起来像这样......

<div class="row">
     //your columns
</div>
<br><br><br>
<div class="row">
    //your columns
</div>

Update: Now that I see your html I see that you are missing the second row. 更新:现在我看到你的HTML我发现你错过了第二行。 Try this: 尝试这个:

<div class="container">
<div class="row">
    <div class="col-md-4"><img src="https://s3.amazonaws.com/codecademy-content/projects/red-eye-photography/p1.jpg" class="img-responsive"></div>
    <div class="col-md-4"><img src="https://s3.amazonaws.com/codecademy-content/projects/red-eye-photography/p2.jpg" class="img-responsive"></div>
    <div class="col-md-4"><img src="https://s3.amazonaws.com/codecademy-content/projects/red-eye-photography/p3.jpg" class="img-responsive"></div>
</div>
<div class="row">
    <div class="col-md-4"><img src="https://s3.amazonaws.com/codecademy-content/projects/red-eye-photography/p4.jpg" class="img-responsive"></div>
    <div class="col-md-4"><img src="https://s3.amazonaws.com/codecademy-content/projects/red-eye-photography/p5.jpg" class="img-responsive"></div>
    <div class="col-md-4">"<img src="https://s3.amazonaws.com/codecademy-content/projects/red-eye-photography/p6.jpg" class="img-responsive"></div>
</div>

  1. You can add the margin-top property to your images. 您可以将margin-top属性添加到图像中。 It makes a space between rows. 它在行之间创建一个空格。

  2. The .img-responsive class has defined in the bootstrap.css . .img-responsive类已在bootstrap.css中定义。 So you don't need to copy all its properties. 所以你不需要复制它的所有属性。 Just add the new ones. 只需添加新的。

For example: 例如:

 @import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css'); .img-responsive { display: block; margin-top: 20px; width: 100%; } 
 <div class="container"> <div class="row"> <div class="col-md-4"><img src="https://s3.amazonaws.com/codecademy-content/projects/red-eye-photography/p1.jpg" class="img-responsive"></div> <div class="col-md-4"><img src="https://s3.amazonaws.com/codecademy-content/projects/red-eye-photography/p2.jpg" class="img-responsive"></div> <div class="col-md-4"><img src="https://s3.amazonaws.com/codecademy-content/projects/red-eye-photography/p3.jpg" class="img-responsive"></div> <div class="col-md-4"><img src="https://s3.amazonaws.com/codecademy-content/projects/red-eye-photography/p4.jpg" class="img-responsive"></div> <div class="col-md-4"><img src="https://s3.amazonaws.com/codecademy-content/projects/red-eye-photography/p5.jpg" class="img-responsive"></div> <div class="col-md-4"><img src="https://s3.amazonaws.com/codecademy-content/projects/red-eye-photography/p6.jpg" class="img-responsive"></div> </div> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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