Image gallery thumbnail size with Bootstrap 4

Paula

I have a very simple responsive image gallery with 6 thumbnails only. In large and medium devices it shows perfectly. However, in mobile view, the thumbnails become way too small. If I add padding, the side margins "break" and they are no longer aligned. Is there a way to make them a bit bigger without "breaking" the side margins? I've posted images so it's easier to understand.

In the image below you can see that the side margins are aligned, but the thumbnails are too small.

This is what I want to achieve

And below you can see what happens when I add padding. The thumbnails are bigger, but the side margins are no longer aligned.

enter image description here

.container {
  max-width: 98%;
  margin: 0 auto;
}

.image-container {
  background-color: #ffffff;
  padding: 10px;
}

.main-image-container img {
  max-width: 100%;
  height: auto;
}

.thumbnail-image-container img {
  max-width: 100%;
  height: auto;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

<div class="container mt-4">
  <div class="row">

    <div class="col-lg-7 image-container">
      <div class="row">
        <div class="col-12 main-image-container img-fluid">
          <img src="https://placeholdit.co//i/1280x720?&text=Test">
        </div>
      </div>
      <div class="row pt-2">
        <div class="col-2 thumbnail-image-container img-fluid">
          <img src="https://placeholdit.co//i/1280x720?&text=Test">
        </div>
        <div class="col-2 thumbnail-image-container img-fluid">
          <img src="https://placeholdit.co//i/1280x720?&text=Test">
        </div>
        <div class="col-2 thumbnail-image-container img-fluid">
          <img src="https://placeholdit.co//i/1280x720?&text=Test">
        </div>
        <div class="col-2 thumbnail-image-container img-fluid">
          <img src="https://placeholdit.co//i/1280x720?&text=Test">
        </div>
        <div class="col-2 thumbnail-image-container img-fluid">
          <img src="https://placeholdit.co//i/1280x720?&text=Test">
        </div>
        <div class="col-2 thumbnail-image-container img-fluid">
          <img src="https://placeholdit.co//i/1280x720?&text=Test">
        </div>


      </div>
    </div>

Shidersz

One solution would be adding the same padding to all col-* classes. Bootstrap have padding classes named p-*. Next example added the p-1 classes to main-image-container and thumbnail-image-container elements.

.container {
  max-width: 98%;
  margin: 0 auto;
}

.image-container {
  background-color: #ffffff;
  padding: 10px;
}

.main-image-container img {
  max-width: 100%;
  height: auto;
}

.thumbnail-image-container img {
  max-width: 100%;
  height: auto;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

<div class="container mt-4">
  <div class="row">

    <div class="col-lg-7 image-container">

      <div class="row">
        <div class="col-12 p-1 main-image-container img-fluid">
          <img src="https://placeholdit.co//i/1280x720?&text=Test">
        </div>
      </div>

      <div class="row pt-2">
        <div class="col-2 p-1 thumbnail-image-container img-fluid">
          <img src="https://placeholdit.co//i/1280x720?&text=Test">
        </div>
        <div class="col-2 p-1 thumbnail-image-container img-fluid">
          <img src="https://placeholdit.co//i/1280x720?&text=Test">
        </div>
        <div class="col-2 p-1 thumbnail-image-container img-fluid">
          <img src="https://placeholdit.co//i/1280x720?&text=Test">
        </div>
        <div class="col-2 p-1 thumbnail-image-container img-fluid">
          <img src="https://placeholdit.co//i/1280x720?&text=Test">
        </div>
        <div class="col-2 p-1 thumbnail-image-container img-fluid">
          <img src="https://placeholdit.co//i/1280x720?&text=Test">
        </div>
        <div class="col-2 p-1 thumbnail-image-container img-fluid">
          <img src="https://placeholdit.co//i/1280x720?&text=Test">
        </div>
      </div>

    </div>

  </div>
</div>

A second solution will be splitting the thumbnails into two rows using the right col-* classes. Like on next example:

.container {
  max-width: 98%;
  margin: 0 auto;
}

.image-container {
  background-color: #ffffff;
  padding: 10px;
}

.main-image-container img {
  max-width: 100%;
  height: auto;
}

.thumbnail-image-container img {
  max-width: 100%;
  height: auto;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

<div class="container mt-4">
  <div class="row">

    <div class="col-lg-7 image-container">

      <div class="row">
        <div class="col-12 main-image-container img-fluid">
          <img src="https://placeholdit.co//i/1280x720?&text=Test">
        </div>
      </div>

      <div class="row pt-1">
        <div class="col-4 col-md-2 mt-2 thumbnail-image-container img-fluid">
          <img src="https://placeholdit.co//i/1280x720?&text=Test">
        </div>
        <div class="col-4 col-md-2 mt-2 thumbnail-image-container img-fluid">
          <img src="https://placeholdit.co//i/1280x720?&text=Test">
        </div>
        <div class="col-4 col-md-2 mt-2 thumbnail-image-container img-fluid">
          <img src="https://placeholdit.co//i/1280x720?&text=Test">
        </div>
        <div class="col-4 col-md-2 mt-2 thumbnail-image-container img-fluid">
          <img src="https://placeholdit.co//i/1280x720?&text=Test">
        </div>
        <div class="col-4 col-md-2 mt-2 thumbnail-image-container img-fluid">
          <img src="https://placeholdit.co//i/1280x720?&text=Test">
        </div>
        <div class="col-4 col-md-2 mt-2 thumbnail-image-container img-fluid">
          <img src="https://placeholdit.co//i/1280x720?&text=Test">
        </div>
      </div>

    </div>

  </div>
</div>

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How to scroll to Next thumbnail image on photo gallery

分類Dev

Bootstrap 4 images thumbnail classes

分類Dev

Image size in nested rows with Bootstrap 4

分類Dev

change default gallery image size on impresspages

分類Dev

Bootstrap image gallery, failing to show starting controls

分類Dev

Using Bootstrap 2.3.2, what is a good method of styling an image gallery

分類Dev

How to increase the size of a thumbnail in QListWidget

分類Dev

Horizontal image view gallery

分類Dev

Opening image in a gallery view

分類Dev

Django Image Grid Gallery

分類Dev

Async Binding Thumbnail Image in UWP

分類Dev

How to replace AVPlayer thumbnail image?

分類Dev

Issue Blueimp gallery Twitter Bootstrap

分類Dev

Responsive card image with fixed height in bootstrap 4

分類Dev

Adding image over parallax (Bootstrap 4)

分類Dev

Image Thumbnail in Web2py: Unable to display the thumbnail

分類Dev

hover Selector not workin on image Gallery

分類Dev

Bootstrap 4: Always display the mobile menu button no matter screen size

分類Dev

How can I change the size of the font in Bootstrap 4 with just CSS?

分類Dev

Getting the next image and previous image from an gallery

分類Dev

Change Image of an ImageButton into an Image from Gallery Android

分類Dev

iOS CoreSpotlight Thumbnail Image from URL

分類Dev

YouTube thumbnail image not loading in android using Glide

分類Dev

jQuery show multiple image thumbnail before upload

分類Dev

Make image File visible in Android Gallery on Lollipop

分類Dev

How to get Image URI from Gallery?

分類Dev

Flutter set image after selecting from gallery

分類Dev

Glide image from gallery to bitmap variable

分類Dev

div that is a link gets shrouded by image gallery

Related 関連記事

  1. 1

    How to scroll to Next thumbnail image on photo gallery

  2. 2

    Bootstrap 4 images thumbnail classes

  3. 3

    Image size in nested rows with Bootstrap 4

  4. 4

    change default gallery image size on impresspages

  5. 5

    Bootstrap image gallery, failing to show starting controls

  6. 6

    Using Bootstrap 2.3.2, what is a good method of styling an image gallery

  7. 7

    How to increase the size of a thumbnail in QListWidget

  8. 8

    Horizontal image view gallery

  9. 9

    Opening image in a gallery view

  10. 10

    Django Image Grid Gallery

  11. 11

    Async Binding Thumbnail Image in UWP

  12. 12

    How to replace AVPlayer thumbnail image?

  13. 13

    Issue Blueimp gallery Twitter Bootstrap

  14. 14

    Responsive card image with fixed height in bootstrap 4

  15. 15

    Adding image over parallax (Bootstrap 4)

  16. 16

    Image Thumbnail in Web2py: Unable to display the thumbnail

  17. 17

    hover Selector not workin on image Gallery

  18. 18

    Bootstrap 4: Always display the mobile menu button no matter screen size

  19. 19

    How can I change the size of the font in Bootstrap 4 with just CSS?

  20. 20

    Getting the next image and previous image from an gallery

  21. 21

    Change Image of an ImageButton into an Image from Gallery Android

  22. 22

    iOS CoreSpotlight Thumbnail Image from URL

  23. 23

    YouTube thumbnail image not loading in android using Glide

  24. 24

    jQuery show multiple image thumbnail before upload

  25. 25

    Make image File visible in Android Gallery on Lollipop

  26. 26

    How to get Image URI from Gallery?

  27. 27

    Flutter set image after selecting from gallery

  28. 28

    Glide image from gallery to bitmap variable

  29. 29

    div that is a link gets shrouded by image gallery

ホットタグ

アーカイブ