Position

Vue Bootstrap 5 Position

Use these helpers for quickly configuring the position of an element.


Basic examples

Fixed top

Position an element at the top of the viewport, from edge to edge. Be sure you understand the ramifications of fixed position in your project; you may need to add additional CSS.

        
            
            <template>
              <div class="fixed-top">...</div>
            </template>
          
        
    

Fixed bottom

Position an element at the bottom of the viewport, from edge to edge. Be sure you understand the ramifications of fixed position in your project; you may need to add additional CSS.

        
            
            <template>
              <div class="fixed-bottom">...</div>
            </template>
          
        
    

Sticky top

Position an element at the top of the viewport, from edge to edge, but only after you scroll past it. The .sticky-top utility uses CSS’s position: sticky, which isn’t fully supported in all browsers.

        
            
            <template>
              <div class="sticky-top">...</div>
            </template>
          
        
    

Responsive sticky top

Responsive variations also exist for .sticky-top utility.

        
            
            <template>
              <div class="sticky-sm-top">Stick to the top on viewports sized SM (small) or wider</div>
              <div class="sticky-md-top">
                Stick to the top on viewports sized MD (medium) or wider
              </div>
              <div class="sticky-lg-top">Stick to the top on viewports sized LG (large) or wider</div>
              <div class="sticky-xl-top">
                Stick to the top on viewports sized XL (extra-large) or wider
              </div>
            </template>
          
        
    

Position values

Quick positioning classes are available, though they are not responsive.

        
            
            <template>
              <div class="position-static">...</div>
              <div class="position-relative">...</div>
              <div class="position-absolute">...</div>
              <div class="position-fixed">...</div>
              <div class="position-sticky">...</div>
            </template>
          
        
    

Arrange elements

Arrange elements easily with the edge positioning utilities. The format is {property}-{position}.

Where property is one of:

  • top - for the vertical top position
  • start - for the horizontal left position (in LTR)
  • bottom - for the vertical bottom position
  • end - for the horizontal right position (in LTR)

Where position is one of:

  • 0 - for 0 edge position
  • 50 - for 50% edge position
  • 100 - for 100% edge position

You can add more position values by adding entries to the $position-values Sass map variable.

        
            
             <template>
              <div class="position-relative position-relative-example">
                <div class="position-absolute top-0 start-0"></div>
                <div class="position-absolute top-0 end-0"></div>
                <div class="position-absolute top-50 start-50"></div>
                <div class="position-absolute bottom-50 end-50"></div>
                <div class="position-absolute bottom-0 start-0"></div>
                <div class="position-absolute bottom-0 end-0"></div>
              </div>
            </template>
          
        
    
        
            
            <style>
              .position-relative-example {
                height: 200px;
                width: 100%;
                background-color: #f5f5f5;
              }
              .position-relative-example div {
                width: 2em;
                height: 2em;
                background-color: #343a40;
                border-radius: 0.25rem;
              }
            </style>
          
        
    

Center elements

In addition, you can also center the elements with the transform utility class .translate-middle.

This class applies the transformations translateX(-50%) and translateY(-50%) to the element which, in combination with the edge positioning utilities, allows you to absolute center an element.

        
            
            <template>
              <div class="position-relative position-relative-example">
                <div class="position-absolute top-0 start-0 translate-middle"></div>
                <div class="position-absolute top-0 start-50 translate-middle"></div>
                <div class="position-absolute top-0 start-100 translate-middle"></div>
                <div class="position-absolute top-50 start-0 translate-middle"></div>
                <div class="position-absolute top-50 start-50 translate-middle"></div>
                <div class="position-absolute top-50 start-100 translate-middle"></div>
                <div class="position-absolute top-100 start-0 translate-middle"></div>
                <div class="position-absolute top-100 start-50 translate-middle"></div>
                <div class="position-absolute top-100 start-100 translate-middle"></div>
              </div>
            </template>
          
        
    
        
            
            <style>
              .position-relative-example {
                height: 200px;
                width: 100%;
                background-color: #f5f5f5;
              }
              .position-relative-example div {
                width: 2em;
                height: 2em;
                background-color: #343a40;
                border-radius: 0.25rem;
              }
            </style>
          
        
    

Additional examples

Here are some real life examples of these classes:

        
            
            <template>
              <MDBBtn color="primary" class="position-relative">
                Mails
                <span 
                  class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-secondary px-1"
                >
                  +99
                  <span class="visually-hidden">unread messages</span>
                </span>
              </MDBBtn>
              <MDBBtn color="dark" class="position-relative">
                Marker
                <svg
                  width="1em"
                  height="1em"
                  viewBox="0 0 16 16"
                  class="position-absolute top-100 start-50 translate-middle bi bi-caret-down-fill"
                  fill="#343a40"
                  xmlns="http://www.w3.org/2000/svg"
                >
                  <path
                    d="M7.247 11.14L2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z"
                  />
                </svg>
              </MDBBtn>
              <MDBBtn color="primary" class="position-relative">
                Alerts
                <span
                  class="position-absolute top-0 start-100 translate-middle badge border border-light rounded-circle bg-danger p-2"
                >
                  <span class="visually-hidden">unread messages</span>
                </span>
              </MDBBtn>
            </template>
          
        
    
        
            
            <script>
              import { MDBBtn } from 'mdb-vue-ui-kit';

              export default {
                components: {
                  MDBBtn,
                },
              };
            </script>
          
        
    
        
            
            <script setup lang="ts">
              import { MDBBtn } from 'mdb-vue-ui-kit';
            </script>
          
        
    

You can use these classes with existing components to create new ones. Remember that you can extend its functionality by adding entries to the $position-values variable.

        
            
            <template>
              <div class="position-relative" style="width: 100%">
                <div class="progress" style="height: 1px">
                  <div
                    class="progress-bar"
                    role="progressbar"
                    style="width: 50%"
                    aria-valuenow="25"
                    aria-valuemin="0"
                    aria-valuemax="100"
                  ></div>
                </div>
                <MDBBtn
                  color="primary"
                  size="sm"
                  class="position-absolute top-0 start-0 translate-middle rounded-pill"
                >
                  1
                </MDBBtn>
                <MDBBtn
                  color="primary"
                  size="sm"
                  class="position-absolute top-0 start-50 translate-middle rounded-pill"
                >
                  2
                </MDBBtn>
                <MDBBtn
                  color="secondary"
                  size="sm"
                  class="position-absolute top-0 start-100 translate-middle rounded-pill"
                >
                  3
                </MDBBtn>
              </div>
            </template>
          
        
    
        
            
            <script>
              import { MDBBtn } from 'mdb-vue-ui-kit';

              export default {
                components: {
                  MDBBtn,
                },
              };
            </script>
          
        
    
        
            
            <script setup lang="ts">
              import { MDBBtn } from 'mdb-vue-ui-kit';
            </script>