HTML, BOOTSTRAP SIDEBAR TUTORIAL

I"m trying to create a layout like the screenshot using Bootstrap 4 but I"m having some problems with making the sidebar fixed & achieving this layout at the same time.

Bạn đang xem: Html, bootstrap sidebar tutorial

Going with a basic example:


It"s possible khổng lồ get this layout but things get tricky once I declare:

.sidebar position: fixed // or absoluteOnce I make the sidebar sticky, the main div starts appearing behind the sidebar instead of next khổng lồ it. Of course it"s possible khổng lồ declare some margin & push it back lớn it"s original position but it makes things complicated for responsiveness.

I feel lượt thích I"m missing something, I read the Bootstrap 4 documentation but I couldn"t find a simple way khổng lồ achieve this layout.


*

Introducing: Trending sort You can now choose khổng lồ sort by Trending, which boosts votes that have happened recently, helping to lớn surface more up-to-date answers.

Trending is based off of the highest score sort & falls back khổng lồ it if no posts are trending.

Xem thêm: Top 8 Loại Sữa Rửa Mặt Hazeline Ngọc Trai Có Tốt Không, Review Sữa Rửa Mặt Hazeline

Try it Dismiss
Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first)
Updated 2020

Here"s an updated answer for the latest Bootstrap 4.0.0. This version has classes that will help you create a sticky or fixed sidebar without the extra CSS....

Use sticky-top:


Demo: https://codeply.com/p/0Co95QlZsH

Also see:Fixed & scrollable column in Bootstrap 4 flexboxBootstrap col fixed positionHow lớn use CSS position sticky khổng lồ keep a sidebar visible with Bootstrap 4Create a responsive navbar sidebar "drawer" in Bootstrap 4?


*

Lorem Ipsum is simply dummy text of the printing & typesetting industry. Lorem Ipsum has been the industry"s standard dummy text ever since the 1500s, when an unknown printer took a galley of type & scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Lorem Ipsum is simply dummy text of the printing và typesetting industry. Lorem Ipsum has been the industry"s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to lớn make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
*

*

I"m using the J.S. To fix a sidebar menu. I"ve tried a lot of solutions with CSS but it"s the simplest way khổng lồ solve it, just showroom J.S. Adding và removing a native BootStrap class: "position-fixed".

The J.S.:

var lateral = false;function fixar() var element, name, arr; element = document.getElementById("minhasidebar"); if (lateral) element.className = element.className.replace( /position-fixed/g, ""); lateral = false; else name = "position-fixed"; arr = element.className.split(" "); if (arr.indexOf(name) == -1) element.className += " " + name; lateral = true; The HTML:

Sidebar:


*

My version:

div#dashmain margin-left:150px; div#dashside position:fixed; width:150px; height:100%;
Thanks for contributing an answer to Stack Overflow!

Please be sure to answer the question. Provide details and share your research!

But avoid

Asking for help, clarification, or responding khổng lồ other answers.Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.


Post Your Answer Discard

By clicking “Post Your Answer”, you agree khổng lồ our terms of service, privacy policy & cookie policy


Not the answer you're looking for? Browse other questions tagged html css twitter-bootstrap bootstrap-4 or ask your own question.


Site design / logo © 2022 Stack Exchange Inc; user contributions licensed under cc by-sa. Rev2022.7.18.42615


Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device và disclose information in accordance with our Cookie Policy.