Saved Bookmarks
| 1. |
Add auto margins to flex items in Bootstrap |
|
Answer» The two classes you need to use for adding auto margins to flex items are .mr-auto and .ml-auto. The OUTPUT shifts items to the right: Let us first see .ml-auto that place items to the left: <!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap Example</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 mt-3"> <h2>Flex Items</h2> <div class="d-flex mb-3 bg-warning"> <div class="p-2 bg-primary">Item 1</div> <div class="p-2 bg-info">Item 2</div> <div class="p-2 ml-auto bg-danger">Item 3</div> </div> </div> </body> </html>The output shifts items to the left: |
|