Code Practice Lab
(current)
Run Code
Live Code Editor
Source Code
<!doctype html> <html lang="en"> <head> <!-- Required meta tags --> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <!-- Bootstrap CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"> <title>Bootstrap Image</title> <style type="text/css"> img{ width:100px; height:100px; } </style> </head> <body> <div class="container mt-4"> <h3 class="text-center">Bootstrap 4 Image Alignment</h3> <div class="row"> <div class="col-sm-12 col-12"> <h4>Image:Left Alignment</h4> <p class="clearfix"> <img src="../code-support/images/bootstrap/bird.jpg" class="img-thumbnail float-left m-3" alt="Thumbnail Image" > Image can be aligned in the left direction by assigning <code>.float-left</code> to the img element base class.Please keep in mind that ,float property should be cleared so that next HTML element can flow in normal </p> <h3>Image:Right Alignment</h3> <p class="clearfix">Image can be aligned in the right direction by assigning <code>.float-right</code> to the img element base class.Please keep in mind that ,float property should be cleared so that next HTML element can flow in normal <img src="../code-support/images/bootstrap/bird.jpg" class="img-thumbnail float-right" alt="Thumbnail Image" > </p> <h3>Image:Center Alignment</h3> <h4>Case:1</h4> <p class="text-justify">Image can be aligned in the center by placing the image inside the container having .text-center class. </p> <div class="text-center"> <img src="../code-support/images/bootstrap/bird.jpg" class="img-thumbnail " alt="Thumbnail Image" > </div><!--/image center alignment--> <h4>Case:2</h4> <p class="text-justify">Image can be aligned in the center by assigning .d-block and .mx-auto to the img element base class. </p> <img src="../code-support/images/bootstrap/bird.jpg" class="img-thumbnail d-block mx-auto " alt="Thumbnail Image"> </div><!--/first column--> </div><!--/row--> </div><!--/container--> <!-- jQuery first, then Popper.js, then Bootstrap JS --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"> </script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script> </body> </html>
Output :
Running