Bootstrap 4 images thumbnail classes

后端 未结 2 2017
情歌与酒
情歌与酒 2021-02-09 14:25

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.

 

        
相关标签:
2条回答
  • 2021-02-09 14:54

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

    Notes:

    • In v4 col-xs was replaced by col-
    • I've added img-fluid utility class in order to make images responsive

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

    0 讨论(0)
  • 2021-02-09 15:01

    In Bootstrap 4 you can do the following.

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

    For the thumbnail, you can use the img-thumbnail class on the img element instead of on the div element.

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

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

    The resulting Bootstrap 4 file would be the following:

        <!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.

    0 讨论(0)
提交回复
热议问题