We are all familiar with the experience of reading a plain text. It delivers the information we need, so you can say it gets the job done. Anyway, in a website or a web application, plain text could never be enough.
The reason is simple: the user wants more from the Internet that they do from a document. Apart from information, they also want design, interactivity, and a billion other things. That is why it is impossible to create a popular website without using images.
Using various classes Bootstrap 4 offers, we can display illustrations in different positions or shapes (say, a Bootstrap thumbnail or a circle). We can also use them to make our Bootstrap image responsive - that means it will be able to react to specific screen size and adapt its size.
Bootstrap Image: Main Tips
- Bootstrap 4 offers image-oriented classes that allow you to position image elements or set the shape of the image container.
- They can also come in handy when you need to make the scaling of your Bootstrap image responsive.
- This tutorial will go over these classes.
In Bootstrap 4, you have classes that change how particular images are displayed. Let's have a closer look at each of them and get a better idea on how they function.
Using the .rounded-circle class you can make the image be displayed inside a circle.
<img src="Example.jpg" class="rounded-circle" alt="Example">
Using the .rounded class, you can make the image be displayed with rounded corners:
<img src="Example.jpg" class="rounded" alt="Example">
Theory is great, but we recommend digging deeper!
Using .img-thumbnail class, you can make the image be displayed inside a bordered Bootstrap thumbnail:
<img src="Example.jpg" class="img-thumbnail" alt="Example">
Aligning Bootstrap Images
There are also classes used to align Bootstrap images horizontally using the CSS float property. .float-left positions the image on the left side of an element, and .float-right positions it on the right:
<img src="Example.jpg" class="float-left" alt="Example"> <img src="Example.jpg" class="float-right" alt="Example">
Making a Bootstrap Image Responsive
Using the .img-fluid class, you can make a Bootstrap image responsive (able to adjust to the screen size).
Look at the example provided below. The class we used here applied height: auto and max-width: 100% to the element it was used with:
<img src="Example.jpg" class="img-fluid" alt="Example">
Bootstrap Image: Summary
- Among the other new classes introduced in Bootstrap 4, a bunch of image-oriented ones was presented.
- You can use them to shape and scale image containers, change the position of image elements and make your Bootstrap image responsive.