Bootstrap 5 Float Responsive
Last Updated : 31 Jul, 2024
Bootstrap 5 Float Responsive is used to make the element floatable depending on the size of the screen. There are two sides where the elements can float one is right and another one is left or you can make it non-floatable.
Bootstrap 5 Float Responsive Class:
- float-start: This class is used to float the element on the left side of the screen.
- float-end: This class is used to float the element on the right side of the screen.
- float-none: This class is used to stop floating the element on the screen.
- float-*-^: The * represents the screen sizes(sm, md, lg, & xl) and ** represents floating positions(start, end & none).
Note: The ** and * are changeable according to your need. The * represents the screen sizes(sm, md, lg, & xl) and ^ represents floating positions(start, end & none)
Syntax:
<div class="float-*-^">
Example 1: In this example, we are going to create 4 div elements that will float on the right part of the screen when the screen size will change.
HTML <!DOCTYPE html> <html> <head> <link href= "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity= "sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous"> </head> <body class="m-3"> <center> <h1 class="text-success"> GeeksforGeeks </h1> <strong>Bootstrap 5 Float Responsive</strong> </center> <div class="container"> <div class="float-sm-end"> I will float to the right when the screen size is small or wider </div> <br> <div class="float-md-end"> I will float to the right when the screen size is medium or wider </div> <br> <div class="float-lg-end"> I will float to the right when the screen size is large or wider </div> <br> <div class="float-xl-end"> I will float to the right when the screen size is extra large or wider </div> </div> </body> </html>
Output:
Example 2: In this example, we will float the element on both sides depending on the screen size. Elements will float left when the screen size is small and extra large and will float right when the screen size is medium and large.
HTML <!DOCTYPE html> <html> <head> <link href= "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity= "sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous"> </head> <body class="m-3"> <center> <h1 class="text-success"> GeeksforGeeks </h1> <strong>Bootstrap 5 Float Responsive</strong> </center> <div class="container"> <div class="float-sm-end float-lg-start"> I will float to the right when the screen size is small or wider </div> <br> <div class="float-md-end float-lg-start"> I will float to the right when the screen size is medium or wider </div> <br> <div class="float-lg-end float-lg-start"> I will float to the right when the screen size is large or wider </div> <br> <div class="float-xl-end float-lg-start"> I will float to the right when the screen size is extra large or wider </div> </div> </body> </html>
Output:
Reference: https://getbootstrap.com/docs/5.0/utilities/float/#responsive
Similar Reads
Bootstrap 5 Responsive Tables Bootstrap 5 Responsive table is used to make a table responsive in two different categories we can make the table always responsive, or make the table responsive on the basis of the breakpoint.Bootstrap 5 Responsive Tables:Table Always Responsive: This is used for horizontal scrolling of the table a
2 min read
Bootstrap 5 Float Bootstrap 5 Float classes use the current viewport size to float an element to the left, right, or deactivate floating. !Important is mentioned to prevent issues with specificity. Please be mindful that flex objects are unaffected by float utilities. This is the replacement of CSS float property tha
3 min read
Bootstrap 5 Images Responsive images Bootstrap 5 Responsive images are used to resize the images according to their parent element and screen sizes. It means, the size of the image should not overflow its parent element and will grow and shrink according to the change in the size of its parent without losing its aspect ratio.Responsive
1 min read
Bootstrap 5 Approach Responsive Bootstrap 5 responsive approach ensures web page visibility across devices. Media queries, such as min-width and occasionally max-width, are used to address responsiveness. Efforts are made to minimize reliance on media queries while accommodating complex component needs.Bootstrap 5 Approach Respons
2 min read
Bootstrap 5 Floating labels Bootstrap 5 floating labels are form labels that float over input fields, improving UX. Wrap form controls like <input>, <label>, <textarea>, <select> inside <div> with class .form-floating. Ensure these elements precede <label> inside the floating <div>.Boo
2 min read