Images: Responsive images, image thumbnails
Sure! Here's a detailed explanation of responsive images and image thumbnails using Bootstrap 4, including code examples with proper indentation.
Responsive Images
In Bootstrap 4, responsive images are images that scale nicely to fit the width of their container. To make an image responsive, you need to add the .img-fluid
class to the image element. This class applies max-width: 100%;
and height: auto;
to the image, ensuring it scales correctly.
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Responsive Images Example</title>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
<h1>Responsive Image</h1>
<img src="https://via.placeholder.com/800x400" class="img-fluid" alt="Responsive image">
</div>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</body>
</html>
Image Thumbnails
Bootstrap 4 provides the .img-thumbnail
class to create an image thumbnail. This class adds a bit of padding and a rounded border to the image. It also ensures the image is responsive.
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Image Thumbnails Example</title>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
<h1>Image Thumbnail</h1>
<img src="https://via.placeholder.com/150" class="img-thumbnail" alt="Thumbnail image">
</div>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</body>
</html>
Combining Responsive and Thumbnail
You can also combine both classes to make an image both responsive and styled as a thumbnail.
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Responsive Thumbnail Example</title>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
<h1>Responsive Thumbnail</h1>
<img src="https://via.placeholder.com/800x400" class="img-fluid img-thumbnail" alt="Responsive thumbnail image">
</div>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</body>
</html>
In these examples, the images will adjust their size according to the container, ensuring they look good on any screen size. The .img-thumbnail
class adds a border and padding to make the images appear as thumbnails, while .img-fluid
ensures they remain responsive.
At Online Learner, we're on a mission to ignite a passion for learning and empower individuals to reach their full potential. Founded by a team of dedicated educators and industry experts, our platform is designed to provide accessible and engaging educational resources for learners of all ages and backgrounds.
Copyright 2023-2025 © All rights reserved.