BootStrap | Positioning an element with Examples
The bootstrap framework provides us a series of classes which allows us to change the position of an element. It provides us five classes which are common in function with the CSS position property. In addition it provides three additional classes for controlling the position of an element.
Common Classes:
- position-static: It works same as the position: static; property of the CSS.
Example:
<!DOCTYPE html><html><head><!-- Custom CSS --><style>h1.text-center{color: green;}div.parent{height: 100px;width: 400px;border: 1px solid black;margin: 0 auto;}p{top: 10px;left: 10px;padding: 2px;border: 1px solid blue;display: inline-block;background: #E3F2FD;}</style><!-- Bootstrap CSS --><linkrel="stylesheet"href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css"integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS"crossorigin="anonymous"><title>Bootstrap Text Utilities</title></head><body><!-- Bootstrap class for making the enire div responsive --><divclass="container"><h1class="text-center">GeeksForGeeks</h1><divclass="parent"><pclass="position-static">position-static</p></div></div><!-- Link JavaScript --><!-- jQuery, Popper.js, Bootstrap JS --><scriptsrc="https://code.jquery.com/jquery-3.3.1.slim.min.js"integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"crossorigin="anonymous"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut"crossorigin="anonymous"></script><scriptsrc="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k"crossorigin="anonymous"></script></body></html>chevron_rightfilter_noneOutput:
- position-relative: It works same as the position: relative; property of the CSS.
Example:
<!DOCTYPE html><html><head><!-- Custom CSS --><style>h1.text-center{color: green;}div.parent{height: 100px;width: 400px;border: 1px solid black;margin: 0 auto;}p{top: 10px;left: 10px;padding: 2px;border: 1px solid blue;display: inline-block;background: #E3F2FD;}</style><!-- Bootstrap CSS --><linkrel="stylesheet"href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css"integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS"crossorigin="anonymous"><title>Bootstrap Text Utilities</title></head><body><!-- Bootstrap class for making the enirediv responsive --><divclass="container"><h1class="text-center">GeeksForGeeks</h1><divclass="parent"><pclass="position-relative">position-relative</p></div></div><!-- Link JavaScript --><!-- jQuery, Popper.js, Bootstrap JS --><scriptsrc="https://code.jquery.com/jquery-3.3.1.slim.min.js"integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"crossorigin="anonymous"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut"crossorigin="anonymous"></script><scriptsrc="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k"crossorigin="anonymous"></script></body></html>chevron_rightfilter_noneOutput:
- position-absolute: It works same as the position: absolute; property of the CSS.
Example:
<!DOCTYPE html><html><head><!-- Custom CSS --><style>h1.text-center{color: green;}div.parent{height: 100px;width: 400px;border: 1px solid black;margin: 0 auto;}p{top: 10px;right: 10px;padding: 2px;border: 1px solid blue;display: inline-block;background: #E3F2FD;}</style><!-- Bootstrap CSS --><linkrel="stylesheet"href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css"integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS"crossorigin="anonymous"><title>Bootstrap Text Utilities</title></head><body><!-- Bootstrap class for making theenire div responsive --><divclass="container"><h1class="text-center">GeeksForGeeks</h1><divclass="parent position-relative"><pclass="position-absolute">position-absolute</p></div></div><!-- Link JavaScript --><!-- jQuery, Popper.js, Bootstrap JS --><scriptsrc="https://code.jquery.com/jquery-3.3.1.slim.min.js"integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"crossorigin="anonymous"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut"crossorigin="anonymous"></script><scriptsrc="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k"crossorigin="anonymous"></script></body></html>chevron_rightfilter_noneOutput:
- position-fixed: It works same as the position: fixed; property of the CSS.
Example:
<!DOCTYPE html><html><head><!-- Custom CSS --><style>h1.text-center{color: green;}div.parent{height: 100px;width: 400px;border: 1px solid black;margin: 0 auto;}p{top: 10px;right: 10px;padding: 2px;border: 1px solid blue;display: inline-block;background: #E3F2FD;}</style><!-- Bootstrap CSS --><linkrel="stylesheet"href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css"integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS"crossorigin="anonymous"><title>Bootstrap Text Utilities</title></head><body><!-- Bootstrap class for making theenire div responsive --><divclass="container"><h1class="text-center">GeeksForGeeks</h1><divclass="parent"><pclass="position-fixed">position-fixed</p></div></div><!-- Link JavaScript --><!-- jQuery, Popper.js, Bootstrap JS --><scriptsrc="https://code.jquery.com/jquery-3.3.1.slim.min.js"integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"crossorigin="anonymous"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut"crossorigin="anonymous"></script><scriptsrc="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k"crossorigin="anonymous"></script></body></html>chevron_rightfilter_noneOutput:
- position-sticky: It works same as the position: sticky; property of the CSS.
Example:
<!DOCTYPE html><html><head><!-- Custom CSS --><style>h1.text-center{color: green;}div.parent{height: 100px;width: 400px;border: 1px solid black;margin: 0 auto;}p{top: 10px;right: 10px;padding: 2px;border: 1px solid blue;display: inline-block;background: #E3F2FD;}</style><!-- Bootstrap CSS --><linkrel="stylesheet"href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css"integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS"crossorigin="anonymous"><title>Bootstrap Text Utilities</title></head><body><!-- Bootstrap class for making theenire div responsive --><divclass="container"><h1class="text-center">GeeksForGeeks</h1><divclass="parent"><pclass="position-sticky">position-sticky</p></div></div><!-- Link JavaScript --><!-- jQuery, Popper.js, Bootstrap JS --><scriptsrc="https://code.jquery.com/jquery-3.3.1.slim.min.js"integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"crossorigin="anonymous"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut"crossorigin="anonymous"></script><scriptsrc="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k"crossorigin="anonymous"></script></body></html>chevron_rightfilter_noneOutput:
Fixed Top
- fixed-top: It makes the element to fix at top of the viewport, from edge to edge.
Example:
<!DOCTYPE html><html><head><!-- Custom CSS --><style>h1.text-center{color: green;margin-top: 30px;}div.parent{height: 100px;width: 400px;border: 1px solid black;margin: 0 auto;}p{text-align: center;padding: 2px;border: 1px solid blue;display: inline-block;background: #E3F2FD;}</style><!-- Bootstrap CSS --><linkrel="stylesheet"href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css"integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS"crossorigin="anonymous"><title>Bootstrap Text Utilities</title></head><body><!-- Bootstrap class for making theenire div responsive --><divclass="container"><h1class="text-center">GeeksForGeeks</h1><divclass="parent"><pclass="fixed-top">fixed-top</p></div></div><!-- Link JavaScript --><!-- jQuery, Popper.js, Bootstrap JS --><scriptsrc="https://code.jquery.com/jquery-3.3.1.slim.min.js"integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"crossorigin="anonymous"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut"crossorigin="anonymous"></script><scriptsrc="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k"crossorigin="anonymous"></script></body></html>chevron_rightfilter_noneOutput:
Fixed Bottom
- fixed-bottom: It makes the element to fix at bottom of the viewport, from edge to edge.
Example:
<!DOCTYPE html><html><head><!-- Custom CSS --><style>h1.text-center{color: green;margin-top: 30px;}div.parent{height: 100px;width: 400px;border: 1px solid black;margin: 0 auto;}p{text-align: center;padding: 2px;border: 1px solid blue;display: inline-block;background: #E3F2FD;/* Overriding default margin-bottomproperty of bootstrap, to make itstick perfectly to the bottom */margin-bottom: 1px !important;}</style><!-- Bootstrap CSS --><linkrel="stylesheet"href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css"integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS"crossorigin="anonymous"><title>Bootstrap Text Utilities</title></head><body><!-- Bootstrap class for making theenire div responsive --><divclass="container"><h1class="text-center">GeeksForGeeks</h1><divclass="parent"><pclass="fixed-bottom">fixed-bottom</p></div></div><!-- Link JavaScript --><!-- jQuery, Popper.js, Bootstrap JS --><scriptsrc="https://code.jquery.com/jquery-3.3.1.slim.min.js"integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"crossorigin="anonymous"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut"crossorigin="anonymous"></script><scriptsrc="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k"crossorigin="anonymous"></script></body></html>chevron_rightfilter_noneOutput:

Sticky Top
- sticky-top: It makes the element to fix at top of the viewport, from edge to edge, after scrolling past the element. Otherwise, it is positioned as static.
Example:<!DOCTYPE html><html><head><style>h1.text-center{color: green;margin-top: 30px;}div.parent{height: 100px;width: 400px;border: 1px solid black;margin: 0 auto;}p{top: 10px;left: 10px;text-align: center;padding: 2px;border: 1px solid blue;display: inline-block;background: #E3F2FD;}</style><!-- Bootstrap CSS --><linkrel="stylesheet"href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css"integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS"crossorigin="anonymous"><title>Bootstrap Text Utilities</title></head><body><!-- Bootstrap class for making theenire div responsive --><divclass="container"><h1class="text-center">GeeksForGeeks</h1><divclass="parent"><pclass="sticky-top">sticky-top</p></div></div><!-- Link JavaScript --><!-- jQuery, Popper.js, Bootstrap JS --><scriptsrc="https://code.jquery.com/jquery-3.3.1.slim.min.js"integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"crossorigin="anonymous"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut"crossorigin="anonymous"></script><scriptsrc="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k"crossorigin="anonymous"></script></body></html>chevron_rightfilter_noneOutput:
Recommended Posts:
- Bootstrap | Sizing an element with Examples
- CSS | Positioning Elements
- Containers in Bootstrap with examples
- Spacing in Bootstrap with Examples
- Popovers in bootstrap with examples
- Bootstrap Buttons with Examples
- Borders in bootstrap with examples
- Vertical alignment in Bootstrap with Examples
- Visibility of elements in bootstrap with Examples
- List group in bootstrap with examples
- Responsive images in Bootstrap with Examples
- Media Objects in Bootstrap with Examples
- Display Property in Bootstrap with Examples
- Input Groups in Bootstrap with Examples
- Colors and gradients in bootstrap with examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



