InterviewSolution
Saved Bookmarks
| 1. |
How to make responsive image in Bootstrap? |
|
Answer» The role of responsive images is to adjust to all screen sizes whether its mobile, desktop or tablet: For responsive image, set the following: max-width: 100%; height: auto;Using the img-fluid CLASS gives you both the above functionalities and scales perfectly on changing the screen size. Here is an example that makes an image responsive: <!DOCTYPE html> <html LANG="EN"> <head> <title>Bootstrap Responsive Image</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" HREF="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script> </head> <body> <div class="container"> <h2>Demo Image</h2> <p>The following image is responsive and will scale perfectly on different screen sizes.</p> <p><strong>Note:</strong> Resize the web BROWSER to check the effect.</p> <img class="img-fluid" src="https://d2o2utebsixu4k.cloudfront.net/media/images/7d7b2bef-2512-4a87-96cb-0bafd0da5048.jpg" alt="Chania" width="460" height="345"> </div> </body> </html>The output displays a responsive image. Resize the web browser to check the effect: |
|