Responsive Images
Responsive Images in Boostrap 4
In boostrap have a classes to make images responsive and control their alignment and sizing.
Making Images Responsive:
Use the .img-fluid class to make images responsive. This class ensures that images scale properly based on the width of the parent container.
Image Alignment and Sizing:
Bootstrap provides utility classes to control image alignment and sizing.
- .float-left and .float-right to float images to the left or right.
- .rounded to add rounded corners to images.
- .img-thumbnail to style images as thumbnails.
- .img-circle to create circular images.
- .img-rounded (deprecated in Bootstrap 4) to add rounded corners to images.
- .text-left, .text-center, .text-right, .text-justify.
<img src="example.jpg" class="rounded mt-3" alt="Rounded Image">
<img src="example.jpg" class="img-thumbnail mt-3" alt="Thumbnail Image">
<img src="example.jpg" class="img-circle mt-3" alt="Circular Image">
Example demonstrating these concepts:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Responsive Images Example</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<!-- Responsive Image -->
<img src="example.jpg" class="img-fluid" alt="Responsive Image">
<!-- Image Alignment -->
<div class="clearfix mt-3"> <!-- Clearfix to contain floated images -->
<img src="example.jpg" class="float-left mr-3" alt="Left Aligned Image">
<img src="example.jpg" class="float-right ml-3" alt="Right Aligned Image">
</div>
<!-- Image Sizing and Styling -->
<img src="example.jpg" class="rounded mt-3" alt="Rounded Image">
<img src="example.jpg" class="img-thumbnail mt-3" alt="Thumbnail Image">
<img src="example.jpg" class="img-circle mt-3" alt="Circular Image">
</div>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js">
</body>
</html>