twitter-bootstrap Bootstrap 4 图像缩略图类

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49102859/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 01:17:14  来源:igfitidea点击:

Bootstrap 4 images thumbnail classes

htmlcsstwitter-bootstrapbootstrap-4twitter-bootstrap-4

提问by csamleong

I got a HTML code in the following using bootstrap 3.3.7, using thumbnail class the images can be resized and fit into the grid perfectly.

我在下面使用 bootstrap 3.3.7 得到了一个 HTML 代码,使用缩略图类可以调整图像的大小并完美地适应网格。

 <!DOCTYPE html>
 <html lang="en">
 <head>
   <meta charset="utf-8">
   <title>Project</title>
   <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
 </head>

<div class="container">
  <h2>Pictures of Coffee</h2>
  <div class="row">
 <div class="col-lg-4 col-xs-6 thumbnail"><img src="https://d2lm6fxwu08ot6.cloudfront.net/img-thumbs/960w/04LDEYRW59.jpg" alt=""></div>
    <div class="col-lg-4 col-xs-6 thumbnail"><img  src="https://d2lm6fxwu08ot6.cloudfront.net/img-thumbs/960w/90V03Q5Y60.jpg" alt=""></div>
    <div class="col-lg-4 col-xs-6 thumbnail"><img  src="https://d2lm6fxwu08ot6.cloudfront.net/img-thumbs/960w/O83SF2RB6D.jpg" alt=""></div>
    <div class="col-lg-4 col-xs-6 thumbnail"><img  src="https://d2lm6fxwu08ot6.cloudfront.net/img-thumbs/960w/5JVPSVP7EI.jpg" alt=""></div>
    <div class="col-lg-4 col-xs-6 thumbnail"><img  src="https://d2lm6fxwu08ot6.cloudfront.net/img-thumbs/960w/C5Y10KIIHA.jpg" alt=""></div>
    <div class="col-lg-4 col-xs-6 thumbnail"><img  src="https://d2lm6fxwu08ot6.cloudfront.net/img-thumbs/960w/YSSFRY5B25.jpg" alt=""></div> 
  </div>
</div>

 </body>
 </html>

However, the thumbnail class doesn't seem to be exist in bootstrap 4.0 https://getbootstrap.com/docs/4.0/layout/grid/To simulate the issue you can try to replace the html link rel with the following

但是,bootstrap 4.0 中似乎不存在缩略图类 https://getbootstrap.com/docs/4.0/layout/grid/要模拟该问题,您可以尝试将 html 链接 rel 替换为以下内容

 <link rel="stylesheet"
 href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
 integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
 crossorigin="anonymous">

You can see the images will be out of places and I would like to know what is the similar class to achieve the same result in 4.0. Or i have to resort to bootstrap 3.3.7 ?

您可以看到图像会出错,我想知道在 4.0 中实现相同结果的类似类是什么。或者我必须求助于引导程序 3.3.7 ?

回答by dippas

According to the docs v4, you are looking for img-thumbnail(which should be used in imgtag instead of col-*-*as you have)

根据文档 v4,您正在寻找img-thumbnail(应该在img标签中使用而不是col-*-*像您那样使用)

Notes:

笔记:

  • In v4 col-xswas replaced by col-
  • I've added img-fluidutility class in order to make images responsive
  • 在 v4 中col-xs被替换为col-
  • 我添加了img-fluid实用程序类以使图像具有响应性

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<div class="container">
  <h2>Pictures of Coffee</h2>
  <div class="row">
    <div class="col-lg-4 col-6 "><img class="img-thumbnail img-fluid" src="https://d2lm6fxwu08ot6.cloudfront.net/img-thumbs/960w/04LDEYRW59.jpg" alt=""></div>
    <div class="col-lg-4 col-6 "><img class="img-thumbnail img-fluid" src="https://d2lm6fxwu08ot6.cloudfront.net/img-thumbs/960w/90V03Q5Y60.jpg" alt=""></div>
    <div class="col-lg-4 col-6 "><img class="img-thumbnail img-fluid" src="https://d2lm6fxwu08ot6.cloudfront.net/img-thumbs/960w/O83SF2RB6D.jpg" alt=""></div>
    <div class="col-lg-4 col-6 "><img class="img-thumbnail img-fluid" src="https://d2lm6fxwu08ot6.cloudfront.net/img-thumbs/960w/5JVPSVP7EI.jpg" alt=""></div>
    <div class="col-lg-4 col-6 "><img class="img-thumbnail img-fluid" src="https://d2lm6fxwu08ot6.cloudfront.net/img-thumbs/960w/C5Y10KIIHA.jpg" alt=""></div>
    <div class="col-lg-4 col-6 "><img class="img-thumbnail img-fluid" src="https://d2lm6fxwu08ot6.cloudfront.net/img-thumbs/960w/YSSFRY5B25.jpg" alt=""></div>
  </div>
</div>

回答by devisscher

In Bootstrap 4 you can do the following.

在 Bootstrap 4 中,您可以执行以下操作。

For columns col-xs-doesn't exist anymore, replace with col-. The default is xs.

对于col-xs-不再存在的列,替换为col-. 默认为xs

For the thumbnail, you can use the img-thumbnailclass on the imgelement instead of on the divelement.

对于缩略图,您可以img-thumbnailimg元素上而不是在div元素上使用类。

Additionally, to achieve 0 padding on each column and row, you can override Bootstrap's padding by adding a custom style rule.

此外,要在每列和每行上实现 0 填充,您可以通过添加自定义样式规则来覆盖 Bootstrap 的填充。

    .row > .col-lg-4,
       .col-6 {
               padding: 0;
       }

The resulting Bootstrap 4 file would be the following:

生成的 Bootstrap 4 文件如下:

    <!DOCTYPE html>
    <html lang="en">

    <head>
        <meta charset="utf-8">
        <title>Project</title>
        <!-- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
        <style>
            .row>.col-lg-4,
            .col-6 {
                padding: 0;
            }

        </style>
    </head>
    <div class="container">
        <h2>Pictures of Coffee</h2>
        <div class="row">
            <div class="col-lg-4 col-6">
                <img class="img-thumbnail" src="https://d2lm6fxwu08ot6.cloudfront.net/img-thumbs/960w/04LDEYRW59.jpg" alt="">
            </div>
            <div class="col-lg-4 col-6">
                <img class="img-thumbnail" src="https://d2lm6fxwu08ot6.cloudfront.net/img-thumbs/960w/90V03Q5Y60.jpg" alt="">
            </div>
            <div class="col-lg-4 col-6">
                <img class="img-thumbnail" src="https://d2lm6fxwu08ot6.cloudfront.net/img-thumbs/960w/O83SF2RB6D.jpg" alt="">
            </div>
            <div class="col-lg-4 col-6">
                <img class="img-thumbnail" src="https://d2lm6fxwu08ot6.cloudfront.net/img-thumbs/960w/5JVPSVP7EI.jpg" alt="">
            </div>
            <div class="col-lg-4 col-6">
                <img class="img-thumbnail" src="https://d2lm6fxwu08ot6.cloudfront.net/img-thumbs/960w/C5Y10KIIHA.jpg" alt="">
            </div>
            <div class="col-lg-4 col-6">
                <img class="img-thumbnail" src="https://d2lm6fxwu08ot6.cloudfront.net/img-thumbs/960w/YSSFRY5B25.jpg" alt="">
            </div>
        </div>
    </div>
    </body>

    </html>

Hope this helps.

希望这可以帮助。